Merge branch 'master' into director-unwrap-result

This commit is contained in:
Olly Betts 2022-03-01 11:34:59 +13:00 committed by GitHub
commit deb7cbf741
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
1099 changed files with 14845 additions and 34359 deletions

View file

@ -93,7 +93,7 @@ int isStructuralDoxygen(String *s) {
const size_t len = strlen(structuralTags[n]);
if (strncmp(slashPointer, structuralTags[n], len) == 0) {
/* Take care to avoid false positives with prefixes of other tags. */
if (slashPointer[len] == '\0' || isspace(slashPointer[len]))
if (slashPointer[len] == '\0' || isspace((int)slashPointer[len]))
return 1;
}
}
@ -214,13 +214,13 @@ void skip_decl(void) {
tok = Scanner_token(scan);
if (tok == 0) {
if (!Swig_error_count()) {
Swig_error(cparse_file, start_line, "Missing semicolon. Reached end of input.\n");
Swig_error(cparse_file, start_line, "Missing semicolon (';'). Reached end of input.\n");
}
return;
}
if (tok == SWIG_TOKEN_LBRACE) {
if (Scanner_skip_balanced(scan,'{','}') < 0) {
Swig_error(cparse_file, start_line, "Missing '}'. Reached end of input.\n");
Swig_error(cparse_file, start_line, "Missing closing brace ('}'). Reached end of input.\n");
}
break;
}
@ -267,7 +267,7 @@ static int yylook(void) {
case SWIG_TOKEN_RBRACE:
num_brace--;
if (num_brace < 0) {
Swig_error(cparse_file, cparse_line, "Syntax error. Extraneous '}'\n");
Swig_error(cparse_file, cparse_line, "Syntax error. Extraneous closing brace ('}')\n");
num_brace = 0;
} else {
return RBRACE;
@ -351,6 +351,9 @@ static int yylook(void) {
}
break;
case SWIG_TOKEN_ELLIPSIS:
return ELLIPSIS;
/* Look for multi-character sequences */
case SWIG_TOKEN_RSTRING:
@ -908,7 +911,7 @@ int yylex(void) {
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) {
if (strcmp(yytext, "_Complex") == 0) {
yylval.type = NewSwigType(T_COMPLEX);
return (TYPE_COMPLEX);
}
@ -1028,8 +1031,23 @@ int yylex(void) {
if (strcmp(yytext, "%warn") == 0)
return (WARN);
/* Note down the apparently unknown directive for error reporting. */
/* Note down the apparently unknown directive for error reporting - if
* we end up reporting a generic syntax error we'll instead report an
* error for his as an unknown directive. Then we treat it as MODULO
* (`%`) followed by an identifier and if that parses OK then
* `cparse_unknown_directive` doesn't get used.
*
* This allows `a%b` to be handled in expressions without a space after
* the operator.
*/
cparse_unknown_directive = NewString(yytext);
String *stext = NewString(yytext + 1);
Seek(stext,0,SEEK_SET);
Setfile(stext,cparse_file);
Setline(stext,cparse_line);
Scanner_push(scan,stext);
Delete(stext);
return (MODULO);
}
/* Have an unknown identifier, as a last step, we'll do a typedef lookup on it. */

View file

@ -1587,6 +1587,9 @@ static String *add_qualifier_to_declarator(SwigType *type, SwigType *qualifier)
Node *node;
};
// Define special token END for end of input.
%token END 0
%token <id> ID
%token <str> HBLOCK
%token <id> POUND
@ -1596,7 +1599,7 @@ static String *add_qualifier_to_declarator(SwigType *type, SwigType *qualifier)
%token <dtype> NUM_INT NUM_FLOAT NUM_UNSIGNED NUM_LONG NUM_ULONG NUM_LONGLONG NUM_ULONGLONG NUM_BOOL
%token <intvalue> TYPEDEF
%token <type> TYPE_INT TYPE_UNSIGNED TYPE_SHORT TYPE_LONG TYPE_FLOAT TYPE_DOUBLE TYPE_CHAR TYPE_WCHAR TYPE_VOID TYPE_SIGNED TYPE_BOOL TYPE_COMPLEX TYPE_TYPEDEF TYPE_RAW TYPE_NON_ISO_INT8 TYPE_NON_ISO_INT16 TYPE_NON_ISO_INT32 TYPE_NON_ISO_INT64
%token LPAREN RPAREN COMMA SEMI EXTERN INIT LBRACE RBRACE PERIOD
%token LPAREN RPAREN COMMA SEMI EXTERN INIT LBRACE RBRACE PERIOD ELLIPSIS
%token CONST_QUAL VOLATILE REGISTER STRUCT UNION EQUAL SIZEOF MODULE LBRACKET RBRACKET
%token BEGINFILE ENDOFFILE
%token ILLEGAL CONSTANT
@ -1671,11 +1674,11 @@ static String *add_qualifier_to_declarator(SwigType *type, SwigType *qualifier)
%type <p> templateparameter ;
%type <id> templcpptype cpptype classkey classkeyopt access_specifier;
%type <node> base_specifier;
%type <str> ellipsis variadic;
%type <str> variadic;
%type <type> type rawtype type_right anon_bitfield_type decltype ;
%type <bases> base_list inherit raw_inherit;
%type <dtype> definetype def_args etype default_delete deleted_definition explicit_default;
%type <dtype> expr exprnum exprcompound valexpr exprmem;
%type <dtype> expr exprnum exprsimple exprcompound valexpr exprmem callparms callptail;
%type <id> ename ;
%type <id> less_valparms_greater;
%type <str> type_qualifier;
@ -1860,7 +1863,7 @@ extend_directive : EXTEND options classkeyopt idcolon LBRACE {
} else {
/* Previous typedef class definition. Use its symbol table.
Deprecated, just the real name should be used.
Note that %extend before the class typedef never worked, only %extend after the class typdef. */
Note that %extend before the class typedef never worked, only %extend after the class typedef. */
prev_symtab = Swig_symbol_setscope(Getattr(cls, "symtab"));
current_class = cls;
SWIG_WARN_NODE_BEGIN(cls);
@ -2010,6 +2013,10 @@ constant_directive : CONSTANT identifier EQUAL definetype SEMI {
Swig_warning(WARN_PARSE_BAD_VALUE,cparse_file,cparse_line,"Bad constant value (ignored).\n");
$$ = 0;
}
| CONSTANT error END {
Swig_error(cparse_file,cparse_line,"Missing semicolon (';') after %%constant.\n");
SWIG_exit(EXIT_FAILURE);
}
;
/* ------------------------------------------------------------
@ -2963,6 +2970,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va
String *nname = NewStringf("__dummy_%d__", cnt++);
Swig_cparse_template_expand(templnode,nname,temparms,tscope);
Setattr(templnode,"sym:name",nname);
SetFlag(templnode,"hidden");
Delete(nname);
Setattr(templnode,"feature:onlychildren", "typemap,typemapitem,typemapcopy,typedef,types,fragment,apply");
if ($3) {
@ -3126,14 +3134,22 @@ c_declaration : c_decl {
Setattr($$,"name",$2);
appendChild($$,n);
while (n) {
SwigType *decl = Getattr(n,"decl");
if (SwigType_isfunction(decl) && !Equal(Getattr(n, "storage"), "typedef")) {
String *s = Getattr(n, "storage");
if (s) {
if (Strstr(s, "thread_local")) {
Insert(s,0,"externc ");
} else if (!Equal(s, "typedef")) {
Setattr(n,"storage","externc");
}
} else {
Setattr(n,"storage","externc");
}
n = nextSibling(n);
}
} else {
Swig_warning(WARN_PARSE_UNDEFINED_EXTERN,cparse_file, cparse_line,"Unrecognized extern type \"%s\".\n", $2);
if (!Equal($2,"C++")) {
Swig_warning(WARN_PARSE_UNDEFINED_EXTERN,cparse_file, cparse_line,"Unrecognized extern type \"%s\".\n", $2);
}
$$ = new_node("extern");
Setattr($$,"name",$2);
appendChild($$,firstChild($5));
@ -3355,9 +3371,9 @@ c_decl_tail : SEMI {
| error {
$$ = 0;
if (yychar == RPAREN) {
Swig_error(cparse_file, cparse_line, "Unexpected ')'.\n");
Swig_error(cparse_file, cparse_line, "Unexpected closing parenthesis (')').\n");
} else {
Swig_error(cparse_file, cparse_line, "Syntax error - possibly a missing semicolon.\n");
Swig_error(cparse_file, cparse_line, "Syntax error - possibly a missing semicolon (';').\n");
}
SWIG_exit(EXIT_FAILURE);
}
@ -3376,6 +3392,10 @@ cpp_alternate_rettype : primitive_type { $$ = $1; }
*/
| TYPE_RAW { $$ = $1; }
| idcolon { $$ = $1; }
| idcolon AND {
$$ = $1;
SwigType_add_reference($$);
}
| decltype { $$ = $1; }
;
@ -4355,18 +4375,30 @@ cpp_template_decl : TEMPLATE LESSTHAN template_parms GREATERTHAN {
parsing_template_declaration = 0;
}
/* Explicit template instantiation */
/* Class template explicit instantiation definition */
| TEMPLATE cpptype idcolon {
Swig_warning(WARN_PARSE_EXPLICIT_TEMPLATE, cparse_file, cparse_line, "Explicit template instantiation ignored.\n");
$$ = 0;
}
/* Explicit template instantiation without the translation unit */
/* Function template explicit instantiation definition */
| TEMPLATE cpp_alternate_rettype idcolon LPAREN parms RPAREN {
Swig_warning(WARN_PARSE_EXPLICIT_TEMPLATE, cparse_file, cparse_line, "Explicit template instantiation ignored.\n");
$$ = 0;
}
/* Class template explicit instantiation declaration (extern template) */
| EXTERN TEMPLATE cpptype idcolon {
Swig_warning(WARN_PARSE_EXPLICIT_TEMPLATE, cparse_file, cparse_line, "Explicit template instantiation ignored.\n");
Swig_warning(WARN_PARSE_EXTERN_TEMPLATE, cparse_file, cparse_line, "Extern template ignored.\n");
$$ = 0;
}
;
/* Function template explicit instantiation declaration (extern template) */
| EXTERN TEMPLATE cpp_alternate_rettype idcolon LPAREN parms RPAREN {
Swig_warning(WARN_PARSE_EXTERN_TEMPLATE, cparse_file, cparse_line, "Extern template ignored.\n");
$$ = 0;
}
;
cpp_template_possible: c_decl {
$$ = $1;
@ -5062,7 +5094,13 @@ extern_string : EXTERN string {
storage_class : EXTERN { $$ = "extern"; }
| extern_string { $$ = $1; }
| extern_string THREAD_LOCAL { $$ = "thread_local"; }
| extern_string THREAD_LOCAL {
if (Equal($1, "extern")) {
$$ = "extern thread_local";
} else {
$$ = "externc thread_local";
}
}
| extern_string TYPEDEF { $$ = "typedef"; }
| STATIC { $$ = "static"; }
| TYPEDEF { $$ = "typedef"; }
@ -5143,7 +5181,7 @@ parm_no_dox : rawtype parameter_declarator {
Setattr($$,"value",$7.val);
}
}
| PERIOD PERIOD PERIOD {
| ELLIPSIS {
SwigType *t = NewString("v(...)");
$$ = NewParmWithoutFileLineInfo(t, 0);
previousNode = currentNode;
@ -5230,6 +5268,20 @@ valparm : parm {
}
;
callparms : valexpr callptail {
$$ = $1;
Printf($$.val, "%s", $2);
}
| empty { $$.val = NewStringEmpty(); }
;
callptail : COMMA valexpr callptail {
$$.val = NewStringf(",%s%s", $2, $3);
$$.type = 0;
}
| empty { $$.val = NewStringEmpty(); }
;
def_args : EQUAL definetype {
$$ = $2;
if ($2.type == T_ERROR) {
@ -5488,16 +5540,16 @@ declarator : pointer notso_direct_declarator {
/* Variadic versions eg. MyClasses&... myIds */
| pointer PERIOD PERIOD PERIOD notso_direct_declarator {
$$ = $5;
| pointer ELLIPSIS notso_direct_declarator {
$$ = $3;
if ($$.type) {
SwigType_push($1,$$.type);
Delete($$.type);
}
$$.type = $1;
}
| pointer AND PERIOD PERIOD PERIOD notso_direct_declarator {
$$ = $6;
| pointer AND ELLIPSIS notso_direct_declarator {
$$ = $4;
SwigType_add_reference($1);
if ($$.type) {
SwigType_push($1,$$.type);
@ -5505,8 +5557,8 @@ declarator : pointer notso_direct_declarator {
}
$$.type = $1;
}
| pointer LAND PERIOD PERIOD PERIOD notso_direct_declarator {
$$ = $6;
| pointer LAND ELLIPSIS notso_direct_declarator {
$$ = $4;
SwigType_add_rvalue_reference($1);
if ($$.type) {
SwigType_push($1,$$.type);
@ -5514,34 +5566,34 @@ declarator : pointer notso_direct_declarator {
}
$$.type = $1;
}
| PERIOD PERIOD PERIOD direct_declarator {
$$ = $4;
| ELLIPSIS direct_declarator {
$$ = $2;
if (!$$.type) $$.type = NewStringEmpty();
}
| AND PERIOD PERIOD PERIOD notso_direct_declarator {
$$ = $5;
| AND ELLIPSIS notso_direct_declarator {
$$ = $3;
$$.type = NewStringEmpty();
SwigType_add_reference($$.type);
if ($5.type) {
SwigType_push($$.type,$5.type);
Delete($5.type);
if ($3.type) {
SwigType_push($$.type,$3.type);
Delete($3.type);
}
}
| LAND PERIOD PERIOD PERIOD notso_direct_declarator {
| LAND ELLIPSIS notso_direct_declarator {
/* Introduced in C++11, move operator && */
/* Adds one S/R conflict */
$$ = $5;
$$ = $3;
$$.type = NewStringEmpty();
SwigType_add_rvalue_reference($$.type);
if ($5.type) {
SwigType_push($$.type,$5.type);
Delete($5.type);
if ($3.type) {
SwigType_push($$.type,$3.type);
Delete($3.type);
}
}
| idcolon DSTAR PERIOD PERIOD PERIOD notso_direct_declarator {
| idcolon DSTAR ELLIPSIS notso_direct_declarator {
SwigType *t = NewStringEmpty();
$$ = $6;
$$ = $4;
SwigType_add_memberpointer(t,$1);
if ($$.type) {
SwigType_push(t,$$.type);
@ -5549,9 +5601,9 @@ declarator : pointer notso_direct_declarator {
}
$$.type = t;
}
| pointer idcolon DSTAR PERIOD PERIOD PERIOD notso_direct_declarator {
| pointer idcolon DSTAR ELLIPSIS notso_direct_declarator {
SwigType *t = NewStringEmpty();
$$ = $7;
$$ = $5;
SwigType_add_memberpointer(t,$2);
SwigType_push($1,t);
if ($$.type) {
@ -5561,8 +5613,8 @@ declarator : pointer notso_direct_declarator {
$$.type = $1;
Delete(t);
}
| pointer idcolon DSTAR AND PERIOD PERIOD PERIOD notso_direct_declarator {
$$ = $8;
| pointer idcolon DSTAR AND ELLIPSIS notso_direct_declarator {
$$ = $6;
SwigType_add_memberpointer($1,$2);
SwigType_add_reference($1);
if ($$.type) {
@ -5571,8 +5623,8 @@ declarator : pointer notso_direct_declarator {
}
$$.type = $1;
}
| pointer idcolon DSTAR LAND PERIOD PERIOD PERIOD notso_direct_declarator {
$$ = $8;
| pointer idcolon DSTAR LAND ELLIPSIS notso_direct_declarator {
$$ = $6;
SwigType_add_memberpointer($1,$2);
SwigType_add_rvalue_reference($1);
if ($$.type) {
@ -5581,9 +5633,9 @@ declarator : pointer notso_direct_declarator {
}
$$.type = $1;
}
| idcolon DSTAR AND PERIOD PERIOD PERIOD notso_direct_declarator {
| idcolon DSTAR AND ELLIPSIS notso_direct_declarator {
SwigType *t = NewStringEmpty();
$$ = $7;
$$ = $5;
SwigType_add_memberpointer(t,$1);
SwigType_add_reference(t);
if ($$.type) {
@ -5592,9 +5644,9 @@ declarator : pointer notso_direct_declarator {
}
$$.type = t;
}
| idcolon DSTAR LAND PERIOD PERIOD PERIOD notso_direct_declarator {
| idcolon DSTAR LAND ELLIPSIS notso_direct_declarator {
SwigType *t = NewStringEmpty();
$$ = $7;
$$ = $5;
SwigType_add_memberpointer(t,$1);
SwigType_add_rvalue_reference(t);
if ($$.type) {
@ -6232,19 +6284,19 @@ primitive_type_list : type_specifier {
} else if (Cmp($1.type,"double") == 0) {
if (Cmp($2.type,"long") == 0) {
$$.type = NewString("long double");
} else if (Cmp($2.type,"complex") == 0) {
$$.type = NewString("double complex");
} else if (Cmp($2.type,"_Complex") == 0) {
$$.type = NewString("double _Complex");
} else {
err = 1;
}
} else if (Cmp($1.type,"float") == 0) {
if (Cmp($2.type,"complex") == 0) {
$$.type = NewString("float complex");
if (Cmp($2.type,"_Complex") == 0) {
$$.type = NewString("float _Complex");
} else {
err = 1;
}
} else if (Cmp($1.type,"complex") == 0) {
$$.type = NewStringf("%s complex", $2.type);
} else if (Cmp($1.type,"_Complex") == 0) {
$$.type = NewStringf("%s _Complex", $2.type);
} else {
err = 1;
}
@ -6294,7 +6346,7 @@ type_specifier : TYPE_INT {
$$.type = 0;
}
| TYPE_COMPLEX {
$$.type = NewString("complex");
$$.type = NewString("_Complex");
$$.us = 0;
}
| TYPE_NON_ISO_INT8 {
@ -6505,23 +6557,38 @@ exprmem : ID ARROW ID {
$$.val = NewStringf("%s->%s", $1, $3);
$$.type = 0;
}
| ID ARROW ID LPAREN callparms RPAREN {
$$.val = NewStringf("%s->%s(%s)", $1, $3, $5);
$$.type = 0;
}
| exprmem ARROW ID {
$$ = $1;
Printf($$.val, "->%s", $3);
}
/* This generates a shift-reduce
| exprmem ARROW ID LPAREN callparms RPAREN {
$$ = $1;
Printf($$.val, "->%s(%s)", $3, $5);
}
| ID PERIOD ID {
$$.val = NewStringf("%s.%s", $1, $3);
$$.type = 0;
}
*/
| ID PERIOD ID LPAREN callparms RPAREN {
$$.val = NewStringf("%s.%s(%s)", $1, $3, $5);
$$.type = 0;
}
| exprmem PERIOD ID {
$$ = $1;
Printf($$.val, ".%s", $3);
}
| exprmem PERIOD ID LPAREN callparms RPAREN {
$$ = $1;
Printf($$.val, ".%s(%s)", $3, $5);
}
;
valexpr : exprnum {
/* Non-compound expression */
exprsimple : exprnum {
$$ = $1;
}
| exprmem {
@ -6536,12 +6603,30 @@ valexpr : exprnum {
$$.val = NewStringf("sizeof(%s)",SwigType_str($3,0));
$$.type = T_ULONG;
}
| SIZEOF PERIOD PERIOD PERIOD LPAREN type parameter_declarator RPAREN {
SwigType_push($6,$7.type);
$$.val = NewStringf("sizeof...(%s)",SwigType_str($6,0));
| SIZEOF ELLIPSIS LPAREN type parameter_declarator RPAREN {
SwigType_push($4,$5.type);
$$.val = NewStringf("sizeof...(%s)",SwigType_str($4,0));
$$.type = T_ULONG;
}
| exprcompound { $$ = $1; }
/* We don't support all valid expressions here currently - e.g.
* sizeof(<unaryop> x) doesn't work - but those are unlikely to
* be seen in real code.
*
* Note: sizeof(x) is not handled here, but instead by the rule
* for sizeof(<type>) because it matches that syntactically.
*/
| SIZEOF LPAREN exprsimple RPAREN {
$$.val = NewStringf("sizeof(%s)", $3.val);
$$.type = T_ULONG;
}
/* `sizeof expr` without parentheses is valid for an expression,
* but not for a type. This doesn't support `sizeof x` in
* addition to the case not supported above.
*/
| SIZEOF exprsimple {
$$.val = NewStringf("sizeof(%s)", $2.val);
$$.type = T_ULONG;
}
| wstring {
$$.val = $1;
$$.rawval = NewStringf("L\"%s\"", $$.val);
@ -6576,6 +6661,11 @@ valexpr : exprnum {
$$.final = 0;
}
;
valexpr : exprsimple { $$ = $1; }
| exprcompound { $$ = $1; }
/* grouping */
| LPAREN expr RPAREN %prec CAST {
$$.val = NewStringf("(%s)",$2.val);
@ -6654,7 +6744,7 @@ valexpr : exprnum {
$$ = $2;
$$.val = NewStringf("*%s",$2.val);
}
;
;
exprnum : NUM_INT { $$ = $1; }
| NUM_FLOAT { $$ = $1; }
@ -6722,16 +6812,24 @@ exprcompound : expr PLUS expr {
$$.val = NewStringf("%s!=%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3));
$$.type = cparse_cplusplus ? T_BOOL : T_INT;
}
/* Sadly this causes 2 reduce-reduce conflicts with templates. FIXME resolve these.
| expr GREATERTHAN expr {
$$.val = NewStringf("%s > %s", COMPOUND_EXPR_VAL($1), COMPOUND_EXPR_VAL($3));
/* Trying to parse `>` in the general case results in conflicts
* in the parser, but all user-reported cases are actually inside
* parentheses and we can handle that case.
*/
| LPAREN expr GREATERTHAN expr RPAREN {
$$.val = NewStringf("%s > %s", COMPOUND_EXPR_VAL($2), COMPOUND_EXPR_VAL($4));
$$.type = cparse_cplusplus ? T_BOOL : T_INT;
}
| expr LESSTHAN expr {
$$.val = NewStringf("%s < %s", COMPOUND_EXPR_VAL($1), COMPOUND_EXPR_VAL($3));
/* Similarly for `<` except trying to handle exprcompound on the
* left side gives a shift/reduce conflict, so also restrict
* handling to non-compound subexpressions there. Again this
* covers all user-reported cases.
*/
| LPAREN exprsimple LESSTHAN expr RPAREN {
$$.val = NewStringf("%s < %s", COMPOUND_EXPR_VAL($2), COMPOUND_EXPR_VAL($4));
$$.type = cparse_cplusplus ? T_BOOL : T_INT;
}
*/
| expr GREATERTHANOREQUALTO expr {
$$.val = NewStringf("%s >= %s", COMPOUND_EXPR_VAL($1), COMPOUND_EXPR_VAL($3));
$$.type = cparse_cplusplus ? T_BOOL : T_INT;
@ -6778,14 +6876,9 @@ exprcompound : expr PLUS expr {
}
;
ellipsis : PERIOD PERIOD PERIOD {
variadic : ELLIPSIS {
$$ = NewString("...");
}
;
variadic : ellipsis {
$$ = $1;
}
| empty {
$$ = 0;
}
@ -6875,11 +6968,11 @@ templcpptype : CLASS {
$$ = (char *)"typename";
if (!inherit_list) last_cpptype = $$;
}
| CLASS PERIOD PERIOD PERIOD {
| CLASS ELLIPSIS {
$$ = (char *)"class...";
if (!inherit_list) last_cpptype = $$;
}
| TYPENAME PERIOD PERIOD PERIOD {
| TYPENAME ELLIPSIS {
$$ = (char *)"typename...";
if (!inherit_list) last_cpptype = $$;
}
@ -7085,8 +7178,8 @@ ctor_initializer : COLON mem_initializer_list
mem_initializer_list : mem_initializer
| mem_initializer_list COMMA mem_initializer
| mem_initializer PERIOD PERIOD PERIOD
| mem_initializer_list COMMA mem_initializer PERIOD PERIOD PERIOD
| mem_initializer ELLIPSIS
| mem_initializer_list COMMA mem_initializer ELLIPSIS
;
mem_initializer : idcolon LPAREN {

View file

@ -338,7 +338,7 @@ String *partial_arg(String *s, String *p) {
}
prefix = NewStringWithSize(cp, (int)(c - cp));
newarg = Copy(s);
Replace(newarg, prefix, "", DOH_REPLACE_ANY | DOH_REPLACE_FIRST);
Replace(newarg, prefix, "", DOH_REPLACE_FIRST);
Delete(prefix);
return newarg;
}
@ -930,6 +930,7 @@ Node *Swig_cparse_template_locate(String *name, Parm *tparms, Symtab *tscope) {
String *nodeType = nodeType(n);
int isclass = 0;
assert(Equal(nodeType, "template"));
(void)nodeType;
isclass = (Equal(Getattr(n, "templatetype"), "class"));
if (!isclass) {
/* If not a templated class we must have a templated function.

View file

@ -364,7 +364,7 @@ extern void DohMemoryDebug(void);
#define Push(s,x) DohInsertitem(s,DOH_BEGIN,x)
#define Len DohLen
#define Data DohData
#define Char (char *) Data
#define Char(X) ((char *) Data(X))
#define Cmp DohCmp
#define Equal DohEqual
#define Setline DohSetline

View file

@ -64,6 +64,7 @@ static void open_files_list_remove(DohFile *f) {
}
Delete(sf);
assert(removed);
(void)removed;
}
/* -----------------------------------------------------------------------------
@ -80,6 +81,7 @@ void DohCloseAllOpenFiles() {
DOHString *sf = Getitem(all_open_files, i);
int check = sscanf(Char(sf), "%p", (void **)&f);
assert(check == 1);
(void)check;
if (f->closeondel) {
if (f->filep) {
check = fclose(f->filep);

View file

@ -836,7 +836,9 @@ static int replace_simple(String *str, char *token, char *rep, int flags, int co
memmove(t, s, (str->str + str->len) - s + 1);
}
} else {
t += (c - s);
if (c) {
t += (c - s);
}
}
s = c;
ic--;

View file

@ -1081,6 +1081,13 @@ bool DoxygenParser::addDoxyCommand(DoxygenParser::TokenList &tokList, const std:
tokList.push_back(Token(COMMAND, cmd));
return true;
} else {
if (cmd.empty()) {
// This actually indicates a bug in the code in this file, as this
// function shouldn't be called at all in this case.
printListError(WARN_DOXYGEN_UNKNOWN_COMMAND, "Unexpected empty Doxygen command.");
return false;
}
// This function is called for the special Doxygen commands, but also for
// HTML commands (or anything that looks like them, actually) and entities.
// We don't recognize all of those, so just ignore them and pass them
@ -1181,6 +1188,11 @@ void DoxygenParser::processWordCommands(size_t &pos, const std::string &line) {
size_t endOfWordPos = getEndOfWordCommand(line, pos);
string cmd = line.substr(pos, endOfWordPos - pos);
if (cmd.empty()) {
// This was a bare backslash, just ignore it.
return;
}
addDoxyCommand(m_tokenList, cmd);
// A flag for whether we want to skip leading spaces after the command
@ -1229,18 +1241,21 @@ void DoxygenParser::processHtmlTags(size_t &pos, const std::string &line) {
// prepend '<' to distinguish HTML tags from doxygen commands
if (!cmd.empty() && addDoxyCommand(m_tokenList, '<' + cmd)) {
// it is a valid HTML command
if (pos == string::npos) {
pos = line.size();
}
if (line[pos] != '>') {
// it should be HTML tag with args,
// for example <A ...>, <IMG ...>, ...
if (isEndHtmlTag) {
m_tokenListIt = m_tokenList.end();
printListError(WARN_DOXYGEN_HTML_ERROR, "Doxygen HTML error for tag " + cmd + ": Illegal end HTML tag without '>' found.");
printListError(WARN_DOXYGEN_HTML_ERROR, "Doxygen HTML error for tag " + cmd + ": Illegal end HTML tag without greater-than ('>') found.");
}
endHtmlPos = line.find(">", pos);
if (endHtmlPos == string::npos) {
m_tokenListIt = m_tokenList.end();
printListError(WARN_DOXYGEN_HTML_ERROR, "Doxygen HTML error for tag " + cmd + ": HTML tag without '>' found.");
printListError(WARN_DOXYGEN_HTML_ERROR, "Doxygen HTML error for tag " + cmd + ": HTML tag without greater-than ('>') found.");
}
// add args of HTML command, like link URL, image URL, ...
m_tokenList.push_back(Token(PLAINSTRING, line.substr(pos, endHtmlPos - pos)));
@ -1254,7 +1269,7 @@ void DoxygenParser::processHtmlTags(size_t &pos, const std::string &line) {
}
}
if (pos != string::npos) {
if (pos < line.size()) {
pos++; // skip '>'
}
} else {

View file

@ -53,13 +53,13 @@ public:
virtual ~DoxygenTranslator();
/*
* Return the documentation for a given node formated for the correct
* Return the documentation for a given node formatted for the correct
* documentation system.
*/
String *getDocumentation(Node *node, const_String_or_char_ptr indentationString);
/*
* Returns truem is the specified node has comment attached.
* Returns true if the specified node has comment attached.
*/
bool hasDocumentation(Node *node);

View file

@ -152,7 +152,7 @@ void JavaDocConverter::fillStaticTables() {
tagHandlers["f{"] = make_pair(&JavaDocConverter::handleTagVerbatim, "");
tagHandlers["warning"] = make_pair(&JavaDocConverter::handleTagMessage, "Warning: ");
// this command just prints it's contents
// this command just prints its contents
// (it is internal command of swig's parser, contains plain text)
tagHandlers["plainstd::string"] = make_pair(&JavaDocConverter::handlePlainString, "");
tagHandlers["plainstd::endl"] = make_pair(&JavaDocConverter::handleNewLine, "");

View file

@ -302,7 +302,7 @@ void PyDocConverter::fillStaticTables() {
tagHandlers["ref"] = make_handler(&PyDocConverter::handleTagRef);
tagHandlers["result"] = tagHandlers["return"] = tagHandlers["returns"] = make_handler(&PyDocConverter::handleTagReturn);
// this command just prints it's contents
// this command just prints its contents
// (it is internal command of swig's parser, contains plain text)
tagHandlers["plainstd::string"] = make_handler(&PyDocConverter::handlePlainString);
tagHandlers["plainstd::endl"] = make_handler(&PyDocConverter::handleNewLine);

View file

@ -195,7 +195,7 @@ private:
typedef std::map<std::string, std::pair<tagHandler, std::string> >TagHandlersMap;
static TagHandlersMap tagHandlers;
// this contains the sections tittles, like 'Arguments:' or 'Notes:', that are printed only once
// this contains the sections titles, like 'Arguments:' or 'Notes:', that are printed only once
static std::map<std::string, std::string> sectionTitles;
// Helper functions for fillStaticTables(): make a new tag handler object.

View file

@ -93,6 +93,7 @@
#define WARN_PARSE_NESTED_TEMPLATE 324
#define WARN_PARSE_NAMED_NESTED_CLASS 325
#define WARN_PARSE_EXTEND_NAME 326
#define WARN_PARSE_EXTERN_TEMPLATE 327
#define WARN_CPP11_LAMBDA 340
#define WARN_CPP11_ALIAS_DECLARATION 341 /* redundant now */
@ -147,7 +148,7 @@
#define WARN_IGNORE_OPERATOR_DELARR 395 /* delete [] */
#define WARN_IGNORE_OPERATOR_REF 396 /* operator *() */
/* 394-399 are reserved */
/* please leave 350-399 free for WARN_IGNORE_OPERATOR_* */
/* -- Type system and typemaps -- */
@ -157,9 +158,9 @@
#define WARN_TYPE_REDEFINED 404
#define WARN_TYPE_RVALUE_REF_QUALIFIER_IGNORED 405
#define WARN_TYPEMAP_SOURCETARGET 450
#define WARN_TYPEMAP_SOURCETARGET 450 /* No longer issued */
#define WARN_TYPEMAP_CHARLEAK 451
#define WARN_TYPEMAP_SWIGTYPE 452
#define WARN_TYPEMAP_SWIGTYPE 452 /* No longer issued */
#define WARN_TYPEMAP_APPLY_UNDEF 453
#define WARN_TYPEMAP_SWIGTYPELEAK 454
@ -212,6 +213,7 @@
#define WARN_LANG_EXTEND_DESTRUCTOR 523
#define WARN_LANG_EXPERIMENTAL 524
#define WARN_LANG_DIRECTOR_FINAL 525
#define WARN_LANG_USING_NAME_DIFFERENT 526
/* -- Doxygen comments -- */
@ -223,7 +225,7 @@
#define WARN_DOXYGEN_UNKNOWN_CHARACTER 565
#define WARN_DOXYGEN_UNEXPECTED_ITERATOR_VALUE 566
/* -- Reserved (600-799) -- */
/* -- Reserved (600-699) -- */
/* -- Language module specific warnings (700 - 899) -- */
@ -277,6 +279,7 @@
#define WARN_JAVA_TYPEMAP_DIRECTORIN_NODESC 824
#define WARN_JAVA_NO_DIRECTORCONNECT_ATTR 825
#define WARN_JAVA_NSPACE_WITHOUT_PACKAGE 826
#define WARN_JAVA_TYPEMAP_INTERFACEMODIFIERS_UNDEF 847
/* please leave 810-829 free for Java */
@ -297,22 +300,11 @@
#define WARN_CSHARP_EXCODE 844
#define WARN_CSHARP_CANTHROW 845
#define WARN_CSHARP_NO_DIRECTORCONNECT_ATTR 846
#define WARN_CSHARP_TYPEMAP_INTERFACEMODIFIERS_UNDEF 847
/* please leave 830-849 free for C# */
#define WARN_MODULA3_TYPEMAP_TYPE_UNDEF 850
#define WARN_MODULA3_TYPEMAP_GETCPTR_UNDEF 851
#define WARN_MODULA3_TYPEMAP_CLASSMOD_UNDEF 852
#define WARN_MODULA3_TYPEMAP_PTRCONSTMOD_UNDEF 853
#define WARN_MODULA3_TYPEMAP_MULTIPLE_RETURN 854
#define WARN_MODULA3_MULTIPLE_INHERITANCE 855
#define WARN_MODULA3_TYPECONSTRUCTOR_UNKNOWN 856
#define WARN_MODULA3_UNKNOWN_PRAGMA 857
#define WARN_MODULA3_BAD_ENUMERATION 858
#define WARN_MODULA3_DOUBLE_ID 859
#define WARN_MODULA3_BAD_IMPORT 860
/* please leave 850-869 free for Modula 3 */
/* 850-860 were used by Modula 3 (removed in SWIG 4.1.0) - avoid reusing for now */
#define WARN_PHP_MULTIPLE_INHERITANCE 870
#define WARN_PHP_UNKNOWN_PRAGMA 871

File diff suppressed because it is too large Load diff

View file

@ -779,6 +779,12 @@ Allocate():
if (Swig_storage_isstatic(n)) {
Setattr(n, "cplus:staticbase", inclass);
} else if (Cmp(Getattr(n, "kind"), "variable") == 0) {
/* Check member variable to determine whether assignment is valid */
if (SwigType_isreference(Getattr(n, "type"))) {
/* Can't assign a class with reference member data */
Setattr(inclass, "allocate:noassign", "1");
}
}
String *name = Getattr(n, "name");

View file

@ -227,7 +227,7 @@ int CFFI::classHandler(Node *n) {
int CFFI::constructorHandler(Node *n) {
#ifdef CFFI_DEBUG
Printf(stderr, "constructor %s\n", Getattr(n, "name"));
Printf(stderr, "constructor %s\n and %s and %s", Getattr(n, "kind"), Getattr(n, "sym:name"), Getattr(n, "allegrocl:old-sym:name"));
Printf(stderr, "constructor %s\n and %s", Getattr(n, "kind"), Getattr(n, "sym:name"));
#endif
Setattr(n, "cffi:constructorfunction", "1");
// Let SWIG generate a global forwarding function.
@ -426,7 +426,6 @@ void CFFI::cleanupFunction(Node *n, Wrapper *f, ParmList *parms) {
if (GetFlag(n, "feature:new")) {
String *tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0);
if (tm) {
Replaceall(tm, "$source", Swig_cresult_name());
Printv(f->code, tm, "\n", NULL);
Delete(tm);
}
@ -546,7 +545,6 @@ int CFFI::functionWrapper(Node *n) {
/* See if there is any return cleanup code */
String *tm = 0;
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
Delete(tm);
}

File diff suppressed because it is too large Load diff

View file

@ -1,515 +0,0 @@
/* -----------------------------------------------------------------------------
* This file is part of SWIG, which is licensed as a whole under version 3
* (or any later version) of the GNU General Public License. Some additional
* terms also apply to certain portions of SWIG. The full details of the SWIG
* license and copyrights can be found in the LICENSE and COPYRIGHT files
* included with the SWIG source code as distributed by the SWIG developers
* and at http://www.swig.org/legal.html.
*
* clisp.cxx
*
* clisp language module for SWIG.
* ----------------------------------------------------------------------------- */
#include "swigmod.h"
static const char *usage = "\
CLISP Options (available with -clisp)\n\
-extern-all - Create clisp definitions for all the functions and\n\
global variables otherwise only definitions for\n\
externed functions and variables are created.\n\
-generate-typedef - Use def-c-type to generate shortcuts according to the\n\
typedefs in the input.\n\
";
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 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(Node *n, 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[]) {
int i;
Preprocessor_define("SWIGCLISP 1", 0);
SWIG_library_directory("clisp");
SWIG_config_file("clisp.swg");
generate_typedef_flag = 0;
extern_all_flag = 0;
for (i = 1; i < argc; i++) {
if (!strcmp(argv[i], "-help")) {
Printf(stdout, "%s\n", usage);
} else if ((Strcmp(argv[i], "-extern-all") == 0)) {
extern_all_flag = 1;
Swig_mark_arg(i);
} else if ((Strcmp(argv[i], "-generate-typedef") == 0)) {
generate_typedef_flag = 1;
Swig_mark_arg(i);
}
}
}
int CLISP::top(Node *n) {
File *f_null = NewString("");
module = Getattr(n, "name");
String *output_filename;
entries = NewList();
/* Get the output file name */
String *outfile = Getattr(n, "outfile");
if (!outfile) {
Printf(stderr, "Unable to determine outfile\n");
SWIG_exit(EXIT_FAILURE);
}
output_filename = NewStringf("%s%s.lisp", SWIG_output_directory(), module);
f_cl = NewFile(output_filename, "w+", SWIG_output_files());
if (!f_cl) {
FileErrorDisplay(output_filename);
SWIG_exit(EXIT_FAILURE);
}
Swig_register_filebyname("header", f_null);
Swig_register_filebyname("begin", f_null);
Swig_register_filebyname("runtime", f_null);
Swig_register_filebyname("wrapper", f_null);
String *header = NewString("");
Swig_banner_target_lang(header, ";;");
Printf(header, "\n(defpackage :%s\n (:use :common-lisp :ffi)", module);
Language::top(n);
Iterator i;
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);
long end = Tell(f_cl);
for (len--; len >= 0; len--) {
end--;
(void)Seek(f_cl, len, SEEK_SET);
int ch = Getc(f_cl);
(void)Seek(f_cl, end, SEEK_SET);
Putc(ch, f_cl);
}
Seek(f_cl, 0, SEEK_SET);
Write(f_cl, Char(header), Len(header));
Delete(f_cl);
return SWIG_OK;
}
int CLISP::functionWrapper(Node *n) {
is_function = 1;
String *storage = Getattr(n, "storage");
if (!extern_all_flag && (!storage || (!Swig_storage_isextern(n) && !Swig_storage_isexternc(n))))
return SWIG_OK;
String *func_name = Getattr(n, "sym:name");
ParmList *pl = Getattr(n, "parms");
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++) {
String *argname = Getattr(p, "name");
// SwigType *argtype;
String *ffitype = get_ffi_type(n, Getattr(p, "type"));
int tempargname = 0;
if (!argname) {
argname = NewStringf("arg%d", argnum);
tempargname = 1;
}
if (!first) {
Printf(f_cl, "\n\t\t");
}
Printf(f_cl, "(%s %s)", argname, ffitype);
first = 0;
Delete(ffitype);
if (tempargname)
Delete(argname);
}
if (ParmList_len(pl) != 0) {
Printf(f_cl, ")\n"); /* finish arg list */
}
String *ffitype = get_ffi_type(n, 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");
Printf(f_cl, "\n(defconstant %s %s)\n", name, converted_value);
Append(entries, name);
Delete(converted_value);
return SWIG_OK;
}
int CLISP::variableWrapper(Node *n) {
is_function = 0;
String *storage = Getattr(n, "storage");
if (!extern_all_flag && (!storage || (!Swig_storage_isextern(n) && !Swig_storage_isexternc(n))))
return SWIG_OK;
String *var_name = Getattr(n, "sym:name");
String *lisp_type = get_ffi_type(n, 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);
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(n, Getattr(n, "type")));
}
return Language::typedefHandler(n);
}
int CLISP::enumDeclaration(Node *n) {
if (getCurrentClass() && (cplus_mode != PUBLIC))
return SWIG_NOWRAP;
is_function = 0;
String *name = Getattr(n, "sym:name");
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);
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");
if (Strcmp(kind, "struct")) {
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)) {
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"));
SWIG_exit(EXIT_FAILURE);
}
String *temp = Copy(Getattr(c, "decl"));
if (temp) {
Append(temp, Getattr(c, "type")); //appending type to the end, otherwise wrong type
String *lisp_type = get_ffi_type(n, temp);
Delete(temp);
String *slot_name = Getattr(c, "sym:name");
Printf(f_cl, "\n\t(%s %s)", slot_name, lisp_type);
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 *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;
}
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);
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;
}
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;
}
String *CLISP::get_ffi_type(Node *n, SwigType *ty) {
Node *node = NewHash();
Setattr(node, "type", ty);
Setfile(node, Getfile(n));
Setline(node, Getline(n));
const String *tm = Swig_typemap_lookup("in", node, "", 0);
Delete(node);
if (tm) {
return NewString(tm);
} else if (SwigType_ispointer(ty)) {
SwigType *cp = Copy(ty);
SwigType_del_pointer(cp);
String *inner_type = get_ffi_type(n, cp);
if (SwigType_isfunction(cp)) {
return inner_type;
}
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);
}
Delete(base_name);
Delete(base);
Delete(cp);
Delete(inner_type);
return str;
} else if (SwigType_isarray(ty)) {
SwigType *cp = Copy(ty);
String *array_dim = SwigType_array_getdim(ty, 0);
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(n, cp);
Delete(cp);
return str;
} else {
SwigType_pop_arrays(cp);
String *inner_type = get_ffi_type(n, cp);
Delete(cp);
int ndim = SwigType_array_ndim(ty);
String *dimension;
if (ndim == 1) {
dimension = array_dim;
} else {
dimension = array_dim;
for (int i = 1; i < ndim; i++) {
array_dim = SwigType_array_getdim(ty, i);
Append(dimension, " ");
Append(dimension, array_dim);
Delete(array_dim);
}
String *temp = dimension;
dimension = NewStringf("(%s)", dimension);
Delete(temp);
}
String *str;
if (is_function)
str = NewStringf("(ffi:c-ptr (ffi:c-array %s %s))", inner_type, dimension);
else
str = NewStringf("(ffi:c-array %s %s)", inner_type, dimension);
Delete(inner_type);
Delete(dimension);
return str;
}
} else if (SwigType_isfunction(ty)) {
SwigType *cp = Copy(ty);
SwigType *fn = SwigType_pop_function(cp);
String *args = NewString("");
ParmList *pl = SwigType_function_parms(fn, n);
if (ParmList_len(pl) != 0) {
Printf(args, "(:arguments ");
}
int argnum = 0, first = 1;
for (Parm *p = pl; p; p = nextSibling(p), argnum++) {
String *argname = Getattr(p, "name");
SwigType *argtype = Getattr(p, "type");
String *ffitype = get_ffi_type(n, argtype);
int tempargname = 0;
if (!argname) {
argname = NewStringf("arg%d", argnum);
tempargname = 1;
}
if (!first) {
Printf(args, "\n\t\t");
}
Printf(args, "(%s %s)", argname, ffitype);
first = 0;
Delete(ffitype);
if (tempargname)
Delete(argname);
}
if (ParmList_len(pl) != 0) {
Printf(args, ")\n"); /* finish arg list */
}
String *ffitype = get_ffi_type(n, cp);
String *str = NewStringf("(ffi:c-function %s \t\t\t\t(:return-type %s))", args, ffitype);
Delete(fn);
Delete(args);
Delete(cp);
Delete(ffitype);
return str;
}
String *str = SwigType_str(ty, 0);
if (str) {
char *st = Strstr(str, "struct");
if (st) {
st += 7;
return NewString(st);
}
char *cl = Strstr(str, "class");
if (cl) {
cl += 6;
return NewString(cl);
}
}
return str;
}
extern "C" Language *swig_clisp(void) {
return new CLISP();
}

View file

@ -901,8 +901,6 @@ public:
// 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);
@ -921,7 +919,6 @@ public:
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);
@ -935,7 +932,6 @@ public:
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);
@ -949,8 +945,6 @@ public:
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"));
@ -982,8 +976,6 @@ public:
/* Return value if necessary */
if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) {
canThrow(n, "out", n);
Replaceall(tm, "$source", Swig_cresult_name()); /* deprecated */
Replaceall(tm, "$target", "jresult"); /* deprecated */
Replaceall(tm, "$result", "jresult");
if (GetFlag(n, "feature:new"))
@ -1011,7 +1003,6 @@ public:
if (GetFlag(n, "feature:new")) {
if ((tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0))) {
canThrow(n, "newfree", n);
Replaceall(tm, "$source", Swig_cresult_name()); /* deprecated */
Printf(f->code, "%s\n", tm);
}
}
@ -1020,7 +1011,6 @@ public:
if (!native_function_flag) {
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
canThrow(n, "ret", n);
Replaceall(tm, "$source", Swig_cresult_name()); /* deprecated */
Printf(f->code, "%s\n", tm);
}
}
@ -2050,7 +2040,8 @@ public:
void emitInterfaceDeclaration(Node *n, String *interface_name, File *f_interface) {
Printv(f_interface, typemapLookup(n, "csimports", Getattr(n, "classtypeobj"), WARN_NONE), "\n", NIL);
Printf(f_interface, "public interface %s", interface_name);
Printv(f_interface, typemapLookup(n, "csinterfacemodifiers", Getattr(n, "classtypeobj"), WARN_CSHARP_TYPEMAP_INTERFACEMODIFIERS_UNDEF), NIL);
Printf(f_interface, " %s", interface_name);
if (List *baselist = Getattr(n, "bases")) {
String *bases = 0;
for (Iterator base = First(baselist); base.item; base = Next(base)) {

View file

@ -160,7 +160,7 @@ String *Swig_method_decl(SwigType *return_base_type, SwigType *decl, const_Strin
SwigType *rettype_stripped = SwigType_strip_qualifiers(rettype);
String *rtype = SwigType_str(rettype, 0);
Append(result, rtype);
if (SwigType_issimple(rettype_stripped) && return_base_type)
if ((SwigType_issimple(rettype_stripped) && return_base_type) || SwigType_isqualifier(rettype))
Append(result, " ");
Delete(rtype);
Delete(rettype_stripped);
@ -175,10 +175,6 @@ String *Swig_method_decl(SwigType *return_base_type, SwigType *decl, const_Strin
if (qualifiers)
Printv(result, " ", qualifiers, NIL);
// Reformat result to how it has been historically
Replaceall(result, ",", ", ");
Replaceall(result, "=", " = ");
Delete(args_string);
Delete(popped_decl);
Delete(qualifiers);

View file

@ -74,7 +74,6 @@ void emit_parameter_variables(ParmList *l, Wrapper *f) {
while (p) {
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");
} else {
@ -87,7 +86,6 @@ void emit_parameter_variables(ParmList *l, Wrapper *f) {
while (p) {
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");
} else {
@ -116,7 +114,6 @@ void emit_attach_parmmaps(ParmList *l, Wrapper *f) {
while (p) {
String *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)) {

File diff suppressed because it is too large Load diff

View file

@ -719,7 +719,6 @@ public:
sprintf(source, "argv[%d]", i);
else
sprintf(source, "s_%d", i);
String *target = Getattr(p, "lname");
if (!args_passed_as_array) {
if (i != 0)
@ -730,8 +729,6 @@ public:
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);
@ -794,7 +791,6 @@ public:
/* 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 {
@ -807,8 +803,6 @@ public:
String *returns_argout = NewString("");
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);
@ -828,7 +822,6 @@ public:
/* 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");
@ -859,8 +852,6 @@ public:
// Now have return value, figure out what to do with it.
if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) {
Replaceall(tm, "$result", "gswig_result");
Replaceall(tm, "$target", "gswig_result");
Replaceall(tm, "$source", Swig_cresult_name());
if (GetFlag(n, "feature:new"))
Replaceall(tm, "$owner", "1");
else
@ -898,13 +889,11 @@ public:
if (GetFlag(n, "feature:new")) {
if ((tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printv(f->code, tm, "\n", NIL);
}
}
// Free any memory allocated by the function being wrapped..
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printv(f->code, tm, "\n", NIL);
}
// Wrap things up (in a manner of speaking)
@ -1141,9 +1130,7 @@ public:
/* Check for a setting of the variable value */
Printf(f->code, "if (s_0 != SCM_UNDEFINED) {\n");
if ((tm = Swig_typemap_lookup("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->code, tm);
} else {
@ -1155,8 +1142,6 @@ public:
// of evaluating or setting)
if ((tm = Swig_typemap_lookup("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->code, tm);
@ -1334,9 +1319,7 @@ public:
// See if there's a typemap
if ((tm = Swig_typemap_lookup("constant", n, name, 0))) {
Replaceall(tm, "$source", value);
Replaceall(tm, "$value", value);
Replaceall(tm, "$target", name);
Printv(f_header, tm, "\n", NIL);
} else {
// Create variable and assign it a value

View file

@ -196,7 +196,7 @@ public:
String *name = Getattr(n, "name") ? Getattr(n, "name") : NewString("<unnamed>");
Swig_warning(WARN_JAVA_NSPACE_WITHOUT_PACKAGE, Getfile(n), Getline(n),
"The nspace feature is used on '%s' without -package. "
"The generated code may not compile as Java does not support types declared in a named package accessing types declared in an unnamed package.\n", name);
"The generated code may not compile as Java does not support types declared in a named package accessing types declared in an unnamed package.\n", SwigType_namestr(name));
}
}
@ -1001,8 +1001,6 @@ public:
// 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);
@ -1027,7 +1025,6 @@ public:
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);
@ -1041,7 +1038,6 @@ public:
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);
@ -1055,8 +1051,6 @@ public:
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"));
@ -1090,8 +1084,6 @@ public:
/* Return value if necessary */
if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) {
addThrows(n, "tmap:out", n);
Replaceall(tm, "$source", Swig_cresult_name()); /* deprecated */
Replaceall(tm, "$target", "jresult"); /* deprecated */
Replaceall(tm, "$result", "jresult");
if (GetFlag(n, "feature:new"))
@ -1118,7 +1110,6 @@ public:
if (GetFlag(n, "feature:new")) {
if ((tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0))) {
addThrows(n, "tmap:newfree", n);
Replaceall(tm, "$source", Swig_cresult_name()); /* deprecated */
Printf(f->code, "%s\n", tm);
}
}
@ -1127,7 +1118,6 @@ public:
if (!native_function_flag) {
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
addThrows(n, "tmap:ret", n);
Replaceall(tm, "$source", Swig_cresult_name()); /* deprecated */
Printf(f->code, "%s\n", tm);
}
}
@ -2145,7 +2135,8 @@ public:
}
Printv(f_interface, typemapLookup(n, "javaimports", Getattr(n, "classtypeobj"), WARN_NONE), "\n", NIL);
Printf(f_interface, "public interface %s", interface_name);
Printv(f_interface, typemapLookup(n, "javainterfacemodifiers", Getattr(n, "classtypeobj"), WARN_JAVA_TYPEMAP_INTERFACEMODIFIERS_UNDEF), NIL);
Printf(f_interface, " %s", interface_name);
if (List *baselist = Getattr(n, "bases")) {
String *bases = 0;
for (Iterator base = First(baselist); base.item; base = Next(base)) {
@ -4835,34 +4826,27 @@ public:
// .'s to delimit namespaces, so we need to replace those with /'s
Replace(internal_classname, NSPACE_SEPARATOR, "/", DOH_REPLACE_ANY);
Wrapper_add_localv(w, "baseclass", "static jclass baseclass", "= 0", NIL);
Printf(w->def, "void %s::swig_connect_director(JNIEnv *jenv, jobject jself, jclass jcls, bool swig_mem_own, bool weak_global) {", director_classname);
Printf(w->def, "static jclass baseclass = swig_new_global_ref(jenv, \"%s\");\n", internal_classname);
Printf(w->def, "if (!baseclass) return;\n");
if (first_class_dmethod != curr_class_dmethod) {
Printf(w->def, "static struct {\n");
Printf(w->def, "const char *mname;\n");
Printf(w->def, "const char *mdesc;\n");
Printf(w->def, "jmethodID base_methid;\n");
Printf(w->def, "} methods[] = {\n");
Printf(w->def, "static SwigDirectorMethod methods[] = {\n");
for (int i = first_class_dmethod; i < curr_class_dmethod; ++i) {
UpcallData *udata = Getitem(dmethods_seq, i);
Printf(w->def, "{ \"%s\", \"%s\", NULL }", Getattr(udata, "method"), Getattr(udata, "fdesc"));
Printf(w->def, "SwigDirectorMethod(jenv, baseclass, \"%s\", \"%s\")", Getattr(udata, "method"), Getattr(udata, "fdesc"));
if (i != curr_class_dmethod - 1)
Putc(',', w->def);
Putc('\n', w->def);
}
Printf(w->def, "};\n");
Printf(w->def, "};");
}
Printf(w->code, "if (swig_set_self(jenv, jself, swig_mem_own, weak_global)) {\n");
Printf(w->code, "if (!baseclass) {\n");
Printf(w->code, "baseclass = jenv->FindClass(\"%s\");\n", internal_classname);
Printf(w->code, "if (!baseclass) return;\n");
Printf(w->code, "baseclass = (jclass) jenv->NewGlobalRef(baseclass);\n");
Printf(w->code, "}\n");
int n_methods = curr_class_dmethod - first_class_dmethod;
@ -4877,12 +4861,8 @@ public:
/* Emit the code to look up the class's methods, initialize the override array */
Printf(w->code, "bool derived = (jenv->IsSameObject(baseclass, jcls) ? false : true);\n");
Printf(w->code, "for (int i = 0; i < %d; ++i) {\n", n_methods);
Printf(w->code, " if (!methods[i].base_methid) {\n");
Printf(w->code, " methods[i].base_methid = jenv->GetMethodID(baseclass, methods[i].mname, methods[i].mdesc);\n");
Printf(w->code, " if (!methods[i].base_methid) return;\n");
Printf(w->code, " }\n");
Printf(w->code, " bool derived = (jenv->IsSameObject(baseclass, jcls) ? false : true);\n");
Printf(w->code, " for (int i = 0; i < %d; ++i) {\n", n_methods);
// Generally, derived classes have a mix of overridden and
// non-overridden methods and it is worth making a GetMethodID
// check during initialization to determine if each method is
@ -4902,8 +4882,8 @@ public:
} else {
Printf(w->code, " swig_override[i] = false;\n");
Printf(w->code, " if (derived) {\n");
Printf(w->code, " jmethodID methid = jenv->GetMethodID(jcls, methods[i].mname, methods[i].mdesc);\n");
Printf(w->code, " swig_override[i] = (methid != methods[i].base_methid);\n");
Printf(w->code, " jmethodID methid = jenv->GetMethodID(jcls, methods[i].name, methods[i].desc);\n");
Printf(w->code, " swig_override[i] = methods[i].methid && (methid != methods[i].methid);\n");
Printf(w->code, " jenv->ExceptionClear();\n");
Printf(w->code, " }\n");
}

View file

@ -166,7 +166,7 @@ public:
*/
virtual int exitClass(Node *) {
return SWIG_OK;
};
}
/**
* Invoked at the beginning of the variableHandler.
@ -178,7 +178,7 @@ public:
*/
virtual int exitVariable(Node *) {
return SWIG_OK;
};
}
/**
* Invoked at the beginning of the functionHandler.
@ -190,7 +190,7 @@ public:
*/
virtual int exitFunction(Node *) {
return SWIG_OK;
};
}
/**
* Invoked by functionWrapper callback after call to Language::functionWrapper.
@ -727,7 +727,7 @@ Node *JSEmitter::getBaseClass(Node *n) {
/* -----------------------------------------------------------------------------
* JSEmitter::emitWrapperFunction() : dispatches emitter functions.
*
* This allows to have small sized, dedicated emitting functions.
* This allows having small sized, dedicated emitting functions.
* All state dependent branching is done here.
* ----------------------------------------------------------------------------- */
@ -994,7 +994,7 @@ int JSEmitter::emitDtor(Node *n) {
{
SWIG_PRV_DATA* t = (SWIG_PRV_DATA*)JSObjectGetPrivate(thisObject);
if(t && t->swigCMemOwn) free ((${type}*)t->swigCObject);
if(t) free(t);
free(t);
}
%}
@ -1007,7 +1007,7 @@ int JSEmitter::emitDtor(Node *n) {
${type}* arg1 = (${type}*)t->swigCObject;
${destructor_action}
}
if(t) free(t);
free(t);
Based on what I saw in the Lua and Ruby modules, I use Getattr(n, "wrap:action")
to decide if the user has a preferred destructor action.
@ -1143,7 +1143,7 @@ int JSEmitter::emitConstant(Node *n) {
String *rawval = Getattr(n, "rawval");
String *value = rawval ? rawval : Getattr(n, "value");
// HACK: forcing usage of cppvalue for v8 (which turned out to fix typdef_struct.i, et. al)
// HACK: forcing usage of cppvalue for v8 (which turned out to fix typedef_struct.i, et. al)
if (State::IsSet(state.globals(FORCE_CPP)) && Getattr(n, "cppvalue") != NULL) {
value = Getattr(n, "cppvalue");
}
@ -1255,7 +1255,7 @@ int JSEmitter::emitFunctionDispatcher(Node *n, bool /*is_member */ ) {
// Note: this dispatcher function gets called after the last overloaded function has been created.
// At this time, n.wrap:name contains the name of the last wrapper function.
// To get a valid function name for the dispatcher function we take the last wrapper name and
// substract the extension "sym:overname",
// subtract the extension "sym:overname",
String *wrap_name = NewString(Getattr(n, "wrap:name"));
String *overname = Getattr(n, "sym:overname");
@ -1575,7 +1575,8 @@ void JSCEmitter::marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, Ma
Printf(arg, "argv[%d]", i);
break;
default:
throw "Illegal state.";
Printf(stderr, "Illegal MarshallingMode.");
SWIG_exit(EXIT_FAILURE);
}
tm = emitInputTypemap(n, p, wrapper, arg);
Delete(arg);
@ -2212,7 +2213,8 @@ void V8Emitter::marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, Mar
Printf(arg, "args[%d]", i);
break;
default:
throw "Illegal state.";
Printf(stderr, "Illegal MarshallingMode.");
SWIG_exit(EXIT_FAILURE);
}
tm = emitInputTypemap(n, p, wrapper, arg);

View file

@ -722,18 +722,18 @@ int Language::typemapDirective(Node *n) {
String *code = Getattr(n, "code");
Parm *kwargs = Getattr(n, "kwargs");
Node *items = firstChild(n);
static int namewarn = 0;
static int nameerror = 0;
if (code && (Strstr(code, "$source") || (Strstr(code, "$target")))) {
Swig_warning(WARN_TYPEMAP_SOURCETARGET, Getfile(n), Getline(n), "Deprecated typemap feature ($source/$target).\n");
if (!namewarn) {
Swig_warning(WARN_TYPEMAP_SOURCETARGET, Getfile(n), Getline(n), "The use of $source and $target in a typemap declaration is deprecated.\n\
Swig_error(Getfile(n), Getline(n), "Obsolete typemap feature ($source/$target).\n");
if (!nameerror) {
Swig_error(Getfile(n), Getline(n), "The use of $source and $target in a typemap declaration is no longer supported.\n\
For typemaps related to argument input (in,ignore,default,arginit,check), replace\n\
$source by $input and $target by $1. For typemaps related to return values (out,\n\
argout,ret,except), replace $source by $1 and $target by $result. See the file\n\
Doc/Manual/Typemaps.html for complete details.\n");
namewarn = 1;
nameerror = 1;
}
}
@ -1320,16 +1320,21 @@ int Language::staticmemberfunctionHandler(Node *n) {
Delete(mrename);
mrename = mangled;
if (Getattr(n, "sym:overloaded") && code) {
Append(cname, Getattr(defaultargs ? defaultargs : n, "sym:overname"));
}
if (code) {
// See Swig_MethodToFunction() for the explanation of this code.
if (Getattr(n, "sym:overloaded")) {
Append(cname, Getattr(defaultargs ? defaultargs : n, "sym:overname"));
} else {
Append(cname, "__SWIG");
}
if (!defaultargs && code) {
/* Hmmm. An added static member. We have to create a little wrapper for this */
String *mangled_cname = Swig_name_mangle(cname);
Swig_add_extension_code(n, mangled_cname, parms, type, code, CPlusPlus, 0);
Setattr(n, "extendname", mangled_cname);
Delete(mangled_cname);
if (!defaultargs) {
/* Hmmm. An added static member. We have to create a little wrapper for this */
String *mangled_cname = Swig_name_mangle(cname);
Swig_add_extension_code(n, mangled_cname, parms, type, code, CPlusPlus, 0);
Setattr(n, "extendname", mangled_cname);
Delete(mangled_cname);
}
}
}
@ -1481,8 +1486,6 @@ int Language::membervariableHandler(Node *n) {
} 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);
@ -3049,8 +3052,6 @@ int Language::variableWrapper(Node *n) {
}
} else {
String *pname0 = Swig_cparm_name(0, 0);
Replace(tm, "$source", pname0, DOH_REPLACE_ANY);
Replace(tm, "$target", name, DOH_REPLACE_ANY);
Replace(tm, "$input", pname0, DOH_REPLACE_ANY);
Setattr(n, "wrap:action", tm);
Delete(tm);

View file

@ -50,7 +50,7 @@
/**** Diagnostics:
With the #define REPORT(), you can change the amount of diagnostics given
This helps me search the parse tree & figure out what is going on inside SWIG
(because its not clear or documented)
(because it's not clear or documented)
*/
#define REPORT(T,D) // no info:
//#define REPORT(T,D) {Printf(stdout,T"\n");} // only title
@ -435,7 +435,7 @@ public:
/* NEW LANGUAGE NOTE:***********************************************
This is it!
you get this one right, and most of your work is done
but its going to take some file to get it working right
but it's going to take some file to get it working right
quite a bit of this is generally boilerplate code
(or stuff I don't understand)
that which matters will have extra added comments
@ -613,13 +613,9 @@ public:
}
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);
if (Getattr(p, "wrap:disown") || (Getattr(p, "tmap:in:disown"))) {
@ -678,7 +674,6 @@ public:
/* 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 {
@ -690,7 +685,6 @@ public:
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");
} else {
@ -709,8 +703,6 @@ public:
// returnval+=GetInt(p,"tmap:argout:numoutputs");
// }
// else returnval++;
Replaceall(tm, "$source", Getattr(p, "lname"));
Replaceall(tm, "$target", Swig_cresult_name());
Replaceall(tm, "$arg", Getattr(p, "emit:input"));
Replaceall(tm, "$input", Getattr(p, "emit:input"));
Printv(outarg, tm, "\n", NIL);
@ -740,7 +732,6 @@ public:
// returnval+=GetInt(tm,"numoutputs");
// }
// else returnval++;
Replaceall(tm, "$source", Swig_cresult_name());
if (GetFlag(n, "feature:new")) {
Replaceall(tm, "$owner", "1");
} else {
@ -762,14 +753,12 @@ public:
/* Look to see if there is any newfree cleanup code */
if (GetFlag(n, "feature:new")) {
if ((tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
}
}
/* See if there is any return cleanup code */
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
}
@ -1002,6 +991,7 @@ public:
// REPORT("variableWrapper", n);
String *lua_name = Getattr(n, "lua:name");
assert(lua_name);
(void)lua_name;
current[VARIABLE] = true;
// let SWIG generate the wrappers
int result = Language::variableWrapper(n);
@ -1073,14 +1063,10 @@ public:
}
if ((tm = Swig_typemap_lookup("consttab", n, name, 0))) {
Replaceall(tm, "$source", value);
Replaceall(tm, "$target", lua_name);
Replaceall(tm, "$value", value);
Replaceall(tm, "$nsname", nsname);
registerConstant(luaCurrentSymbolNSpace(), tm);
} else if ((tm = Swig_typemap_lookup("constcode", n, name, 0))) {
Replaceall(tm, "$source", value);
Replaceall(tm, "$target", lua_name);
Replaceall(tm, "$value", value);
Replaceall(tm, "$nsname", nsname);
Printf(f_init, "%s\n", tm);
@ -1109,8 +1095,6 @@ public:
Setattr(n_v2, "sym:name", lua_name_v2);
tm_v2 = Swig_typemap_lookup("consttab", n_v2, name, 0);
if (tm_v2) {
Replaceall(tm_v2, "$source", value);
Replaceall(tm_v2, "$target", lua_name_v2);
Replaceall(tm_v2, "$value", value);
Replaceall(tm_v2, "$nsname", nsname);
registerConstant(getNSpace(), tm_v2);
@ -1122,8 +1106,6 @@ public:
Swig_restore(n);
return SWIG_ERROR;
}
Replaceall(tm_v2, "$source", value);
Replaceall(tm_v2, "$target", lua_name_v2);
Replaceall(tm_v2, "$value", value);
Replaceall(tm_v2, "$nsname", nsname);
Printf(f_init, "%s\n", tm_v2);
@ -2071,8 +2053,8 @@ public:
if (GetFlag(carrays_hash, "lua:class_instance")) {
String *static_cls = Getattr(carrays_hash, "lua:class_instance:static_hash");
assert(static_cls);
// static_cls is swig_lua_namespace. This structure can't be use with eLua(LTR)
// Instead structure describing its methods isused
// static_cls is swig_lua_namespace. This structure can't be used with eLua(LTR)
// Instead a structure describing its methods is used
String *static_cls_cname = Getattr(static_cls, "methods:name");
assert(static_cls_cname);
Printv(metatable_tab, tab4, "{LSTRKEY(\".static\"), LROVAL(", static_cls_cname, ")},\n", NIL);
@ -2243,36 +2225,6 @@ public:
};
/* NEW LANGUAGE NOTE:***********************************************
in order to add you language into swig, you need to make the following changes:
- write this file (obviously)
- add into the makefile (not 100% clear on how to do this)
- edit swigmain.cxx to add your module
near the top of swigmain.cxx, look for this code & add you own codes
======= begin change ==========
extern "C" {
Language *swig_tcl(void);
Language *swig_python(void);
//etc,etc,etc...
Language *swig_lua(void); // this is my code
}
//etc,etc,etc...
swig_module modules[] = {
{"-guile", swig_guile, "Guile"},
{"-java", swig_java, "Java"},
//etc,etc,etc...
{"-lua", swig_lua, "Lua"}, // this is my code
{NULL, NULL, NULL} // this must come at the end of the list
};
======= end change ==========
This is all that is needed
NEW LANGUAGE NOTE:END ************************************************/
/* -----------------------------------------------------------------------------
* swig_lua() - Instantiate module
* ----------------------------------------------------------------------------- */

View file

@ -137,7 +137,7 @@ static const char *usage4 = (const char *) "\
-oh <headfile> - Set name of C++ output header file for directors to <headfile>\n\
-outcurrentdir - Set default output dir to current dir instead of input file's path\n\
-outdir <dir> - Set language specific files output directory to <dir>\n\
-pcreversion - Display PCRE version information\n\
-pcreversion - Display PCRE2 version information\n\
-small - Compile in virtual elimination and compact mode\n\
-swiglib - Report location of SWIG library and exit\n\
-templatereduce - Reduce all the typedefs in templates\n\
@ -477,7 +477,10 @@ static void getoptions(int argc, char *argv[]) {
Swig_mark_arg(i);
} else if (strncmp(argv[i], "-D", 2) == 0) {
String *d = NewString(argv[i] + 2);
Replace(d, "=", " ", DOH_REPLACE_ANY | DOH_REPLACE_FIRST);
if (Replace(d, "=", " ", DOH_REPLACE_FIRST) == 0) {
// Match C preprocessor behaviour whereby -DFOO sets FOO=1.
Append(d, " 1");
}
Preprocessor_define((DOH *) d, 0);
Delete(d);
// Create a symbol

File diff suppressed because it is too large Load diff

View file

@ -322,8 +322,6 @@ public:
}
// 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);
@ -343,7 +341,6 @@ public:
/* 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 {
@ -355,8 +352,6 @@ public:
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);
@ -371,7 +366,6 @@ public:
/* 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 {
@ -385,8 +379,6 @@ public:
// Now have return value, figure out what to do with it.
if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) {
Replaceall(tm, "$source", Swig_cresult_name());
Replaceall(tm, "$target", "values[0]");
Replaceall(tm, "$result", "values[0]");
if (GetFlag(n, "feature:new"))
Replaceall(tm, "$owner", "1");
@ -408,14 +400,12 @@ public:
if (GetFlag(n, "feature:new")) {
if ((tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printv(f->code, tm, "\n", NIL);
}
}
// Free any memory allocated by the function being wrapped..
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printv(f->code, tm, "\n", NIL);
}
// Wrap things up (in a manner of speaking)
@ -453,7 +443,7 @@ public:
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);
Printf(df->code, "return NULL;\n", iname);
Printf(df->code, "return NULL;\n");
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);
@ -521,8 +511,6 @@ public:
/* Check for a setting of the variable value */
Printf(f->code, "if (argc) {\n");
if ((tm = Swig_typemap_lookup("varin", n, name, 0))) {
Replaceall(tm, "$source", "argv[0]");
Replaceall(tm, "$target", name);
Replaceall(tm, "$input", "argv[0]");
Replaceall(tm, "$argnum", "1");
emit_action_code(n, f->code, tm);
@ -535,8 +523,6 @@ public:
// of evaluating or setting)
if ((tm = Swig_typemap_lookup("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->code, tm);
@ -609,9 +595,7 @@ public:
Printv(rvalue, "'", temp, "'", NIL);
}
if ((tm = Swig_typemap_lookup("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

View file

@ -396,7 +396,7 @@ void Swig_nested_name_unnamed_c_structs(Node *n) {
Delete(ins);
Delattr(c, "nested:outer");
} else {
// global unnamed struct - ignore it and it's instances
// global unnamed struct - ignore it and its instances
SetFlag(c, "feature:ignore");
while (next && Getattr(next, "nested:unnamedtype") == c) {
SetFlag(next, "feature:ignore");

View file

@ -407,7 +407,7 @@ public:
printf("Fatal error. SwigType_del_pointer applied to non-pointer.\n");
abort();
}
Replace(t, "r.", "", DOH_REPLACE_ANY | DOH_REPLACE_FIRST);
Replace(t, "r.", "", DOH_REPLACE_FIRST);
}
void oc_SwigType_del_array(SwigType *t) {
@ -590,8 +590,6 @@ public:
}
// 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);
@ -611,7 +609,6 @@ public:
/* 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 {
@ -623,8 +620,6 @@ public:
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")));
@ -640,7 +635,6 @@ public:
/* 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 {
@ -681,8 +675,6 @@ public:
String *actioncode = emit_action(n);
if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) {
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);
@ -701,14 +693,12 @@ public:
if (GetFlag(n, "feature:new")) {
if ((tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", "swig_result");
Printv(f->code, tm, "\n", NIL);
}
}
/* See if there is any return cleanup code */
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
Delete(tm);
}
@ -716,7 +706,6 @@ public:
// Free any memory allocated by the function being wrapped..
if ((tm = Swig_typemap_lookup("swig_result", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printv(f->code, tm, "\n", NIL);
}
// Wrap things up (in a manner of speaking)
@ -853,13 +842,9 @@ public:
/* Check for a setting of the variable value */
Printf(f->code, "if (args != Val_int(0)) {\n");
if ((tm = Swig_typemap_lookup("varin", n, name, 0))) {
Replaceall(tm, "$source", "args");
Replaceall(tm, "$target", name);
Replaceall(tm, "$input", "args");
emit_action_code(n, f->code, tm);
} else if ((tm = Swig_typemap_lookup("in", n, name, 0))) {
Replaceall(tm, "$source", "args");
Replaceall(tm, "$target", name);
Replaceall(tm, "$input", "args");
emit_action_code(n, f->code, tm);
} else {
@ -871,13 +856,9 @@ public:
// of evaluating or setting)
if ((tm = Swig_typemap_lookup("varout", n, name, 0))) {
Replaceall(tm, "$source", name);
Replaceall(tm, "$target", "swig_result");
Replaceall(tm, "$result", "swig_result");
emit_action_code(n, f->code, tm);
} else if ((tm = Swig_typemap_lookup("out", n, name, 0))) {
Replaceall(tm, "$source", name);
Replaceall(tm, "$target", "swig_result");
Replaceall(tm, "$result", "swig_result");
emit_action_code(n, f->code, tm);
} else {

View file

@ -611,9 +611,7 @@ public:
sprintf(source, "args(%d)", j);
Setattr(p, "emit:input", source);
Replaceall(tm, "$source", Getattr(p, "emit:input"));
Replaceall(tm, "$input", Getattr(p, "emit:input"));
Replaceall(tm, "$target", Getattr(p, "lname"));
if (Getattr(p, "wrap:disown") || (Getattr(p, "tmap:in:disown"))) {
Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN");
@ -658,7 +656,6 @@ public:
// 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 {
@ -681,7 +678,6 @@ public:
}
}
if (tm && (Len(tm) != 0)) {
Replaceall(tm, "$source", Getattr(p, "lname"));
Printv(cleanup, tm, "\n", NIL);
}
p = Getattr(p, "tmap:freearg:next");
@ -694,8 +690,6 @@ public:
String *outarg = NewString("");
for (p = l; p;) {
if ((tm = Getattr(p, "tmap:argout"))) {
Replaceall(tm, "$source", Getattr(p, "lname"));
Replaceall(tm, "$target", "_outp");
Replaceall(tm, "$result", "_outp");
Replaceall(tm, "$arg", Getattr(p, "emit:input"));
Replaceall(tm, "$input", Getattr(p, "emit:input"));
@ -723,8 +717,6 @@ public:
// Return the function value
if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) {
Replaceall(tm, "$source", Swig_cresult_name());
Replaceall(tm, "$target", "_outv");
Replaceall(tm, "$result", "_outv");
if (GetFlag(n, "feature:new"))
@ -745,13 +737,11 @@ public:
if (GetFlag(n, "feature:new")) {
if ((tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
}
}
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Replaceall(tm, "$result", "_outv");
Printf(f->code, "%s\n", tm);
Delete(tm);
@ -815,7 +805,7 @@ public:
Printf(tmp, "}");
Wrapper_add_local(f, "argv", tmp);
Printv(f->code, dispatch, "\n", NIL);
Printf(f->code, "error(\"No matching function for overload\");\n", iname);
Printf(f->code, "error(\"No matching function for overload\");\n");
Printf(f->code, "return octave_value_list();\n");
Printv(f->code, "}\n", NIL);
@ -849,8 +839,6 @@ public:
if (is_assignable(n)) {
Setattr(n, "wrap:name", setname);
if ((tm = Swig_typemap_lookup("varin", n, name, 0))) {
Replaceall(tm, "$source", "args(0)");
Replaceall(tm, "$target", name);
Replaceall(tm, "$input", "args(0)");
if (Getattr(n, "tmap:varin:implicitconv")) {
Replaceall(tm, "$implicitconv", get_implicitconv_flag(n));
@ -874,8 +862,6 @@ public:
Octave_begin_function(n, getf->def, getname, getwname, true);
Wrapper_add_local(getf, "obj", "octave_value obj");
if ((tm = Swig_typemap_lookup("varout", n, name, 0))) {
Replaceall(tm, "$source", name);
Replaceall(tm, "$target", "obj");
Replaceall(tm, "$result", "obj");
addfail = emit_action_code(n, getf->code, tm);
Delete(tm);
@ -920,8 +906,6 @@ public:
value = wname;
}
if ((tm = Swig_typemap_lookup("constcode", n, name, 0))) {
Replaceall(tm, "$source", value);
Replaceall(tm, "$target", name);
Replaceall(tm, "$value", cppvalue ? cppvalue : value);
Replaceall(tm, "$nsname", iname);
Printf(f_init, "%s\n", tm);

View file

@ -21,6 +21,7 @@
String *argv_template_string;
String *argc_template_string;
namespace {
struct Overloaded {
Node *n; /* Node */
int argc; /* Argument count */
@ -28,6 +29,7 @@ struct Overloaded {
int error; /* Ambiguity error */
bool implicitconv_function; /* For ordering implicitconv functions*/
};
}
static int fast_dispatch_mode = 0;
static int cast_dispatch_mode = 0;
@ -809,7 +811,7 @@ String *Swig_overload_dispatch(Node *n, const_String_or_char_ptr fmt, int *maxar
}
if (num_arguments) {
Printf(f, "int _v;\n");
Printf(f, "int _v = 0;\n");
}
int num_braces = 0;

View file

@ -445,13 +445,7 @@ public:
Printv(magic,
"#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n",
"#ifdef PERL_OBJECT\n",
"#define MAGIC_CLASS _wrap_", underscore_module, "_var::\n",
"class _wrap_", underscore_module, "_var : public CPerlObj {\n",
"public:\n",
"#else\n",
"#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);
@ -470,7 +464,6 @@ public:
/* Dump out variable wrappers */
Printv(magic, "\n\n#ifdef PERL_OBJECT\n", "};\n", "#endif\n", NIL);
Printv(magic, "\n#ifdef __cplusplus\n}\n#endif\n", NIL);
Printf(f_header, "%s\n", magic);
@ -725,14 +718,11 @@ public:
/* Produce string representation of source and target arguments */
sprintf(source, "ST(%d)", i);
String *target = Getattr(p, "lname");
if (i >= num_required) {
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 */
@ -767,7 +757,6 @@ public:
/* 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 {
@ -778,7 +767,6 @@ public:
/* 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);
@ -793,8 +781,6 @@ public:
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");
@ -855,8 +841,6 @@ public:
if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) {
SwigType *t = Getattr(n, "type");
Replaceall(tm, "$source", Swig_cresult_name());
Replaceall(tm, "$target", "ST(argvi)");
Replaceall(tm, "$result", "ST(argvi)");
if (is_shadow(t)) {
Replaceall(tm, "$shadow", "SWIG_SHADOW");
@ -884,13 +868,11 @@ public:
if (GetFlag(n, "feature:new")) {
if ((tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
}
}
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
}
@ -995,8 +977,6 @@ public:
/* Check for a few typemaps */
tm = Swig_typemap_lookup("varin", n, name, 0);
if (tm) {
Replaceall(tm, "$source", "sv");
Replaceall(tm, "$target", name);
Replaceall(tm, "$input", "sv");
/* Printf(setf->code,"%s\n", tm); */
emit_action_code(n, setf->code, tm);
@ -1019,9 +999,7 @@ public:
Printv(getf->code, tab4, "MAGIC_PPERL\n", NIL);
if ((tm = Swig_typemap_lookup("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 {
@ -1111,8 +1089,6 @@ public:
}
if ((tm = Swig_typemap_lookup("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");
@ -1121,8 +1097,6 @@ public:
}
Printf(constant_tab, "%s,\n", tm);
} else if ((tm = Swig_typemap_lookup("constcode", n, name, 0))) {
Replaceall(tm, "$source", value);
Replaceall(tm, "$target", name);
Replaceall(tm, "$value", value);
if (is_shadow(type)) {
Replaceall(tm, "$shadow", "SWIG_SHADOW");
@ -2341,7 +2315,7 @@ public:
Replaceall(tm, "$error", "ERRSV");
Printv(w->code, Str(tm), "\n", NIL);
} else {
Printf(w->code, " Swig::DirectorMethodException::raise(ERRSV);\n", classname, pyname);
Printf(w->code, " Swig::DirectorMethodException::raise(ERRSV);\n");
}
Append(w->code, "}\n");
Delete(tm);

File diff suppressed because it is too large Load diff

View file

@ -1,904 +0,0 @@
/* -----------------------------------------------------------------------------
* This file is part of SWIG, which is licensed as a whole under version 3
* (or any later version) of the GNU General Public License. Some additional
* terms also apply to certain portions of SWIG. The full details of the SWIG
* license and copyrights can be found in the LICENSE and COPYRIGHT files
* included with the SWIG source code as distributed by the SWIG developers
* and at http://www.swig.org/legal.html.
*
* pike.cxx
*
* Pike language module for SWIG.
* ----------------------------------------------------------------------------- */
/*
* Notes:
*
* - The current approach used for "out" typemaps is inconsistent with
* how "out" typemaps are handled by other language modules. Instead
* of converting the C/C++ type ($1) to a Pike object type (e.g. a
* struct svalue), we're just calling the appropriate push_XXX
* (e.g. push_int) to push the return value onto the stack.
*
* - Pike classes can't have static member functions or data, so we need
* to find some other appropriate mapping for C++ static member functions
* and data.
*
* - Pike doesn't seem to provide any default way to print the memory
* address, etc. for extension objects. Should we do something here?
*
*/
#include "swigmod.h"
#include <ctype.h> // for isalnum()
static const char *usage = "\
Pike Options (available with -pike)\n\
[no additional options]\n\
\n";
class PIKE:public Language {
private:
File *f_begin;
File *f_runtime;
File *f_header;
File *f_wrappers;
File *f_init;
File *f_classInit;
String *PrefixPlusUnderscore;
int current;
// Wrap modes
enum {
NO_CPP,
MEMBER_FUNC,
CONSTRUCTOR,
DESTRUCTOR,
MEMBER_VAR,
CLASS_CONST,
STATIC_FUNC,
STATIC_VAR
};
public:
/* ---------------------------------------------------------------------
* PIKE()
*
* Initialize member data
* --------------------------------------------------------------------- */
PIKE() {
f_begin = 0;
f_runtime = 0;
f_header = 0;
f_wrappers = 0;
f_init = 0;
f_classInit = 0;
PrefixPlusUnderscore = 0;
current = NO_CPP;
}
/* ---------------------------------------------------------------------
* main()
*
* Parse command line options and initializes variables.
* --------------------------------------------------------------------- */
virtual void main(int argc, char *argv[]) {
/* Set location of SWIG library */
SWIG_library_directory("pike");
/* 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);
}
}
}
/* Add a symbol to the parser for conditional compilation */
Preprocessor_define("SWIGPIKE 1", 0);
/* Set language-specific configuration file */
SWIG_config_file("pike.swg");
/* Set typemap language */
SWIG_typemap_lang("pike");
/* Enable overloaded methods support */
allow_overloading();
}
/* ---------------------------------------------------------------------
* top()
* --------------------------------------------------------------------- */
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_begin = NewFile(outfile, "w", SWIG_output_files());
if (!f_begin) {
FileErrorDisplay(outfile);
SWIG_exit(EXIT_FAILURE);
}
f_runtime = NewString("");
f_init = NewString("");
f_classInit = 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("begin", f_begin);
Swig_register_filebyname("runtime", f_runtime);
Swig_register_filebyname("init", f_init);
Swig_register_filebyname("classInit", f_classInit);
/* Standard stuff for the SWIG runtime section */
Swig_banner(f_begin);
Printf(f_runtime, "\n\n#ifndef SWIGPIKE\n#define SWIGPIKE\n#endif\n\n");
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", "%n%c_create");
Swig_name_register("destroy", "%n%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_runtime, f_begin);
Dump(f_header, f_begin);
Dump(f_wrappers, f_begin);
Wrapper_pretty_print(f_init, f_begin);
Delete(f_header);
Delete(f_wrappers);
Delete(f_init);
Delete(f_classInit);
Delete(f_runtime);
Delete(f_begin);
/* Done */
return SWIG_OK;
}
/* ------------------------------------------------------------
* validIdentifier()
* ------------------------------------------------------------ */
virtual int validIdentifier(String *s) {
char *c = Char(s);
const char *c0 = c;
const char *c1 = c0 + 1;
while (*c) {
if (*c == '`' && c == c0) {
c++;
continue;
}
if ((*c == '+' || *c == '-' || *c == '*' || *c == '/') && c == c1) {
c++;
continue;
}
if (!(isalnum(*c) || (*c == '_')))
return 0;
c++;
}
return 1;
}
/* ------------------------------------------------------------
* importDirective()
* ------------------------------------------------------------ */
virtual int importDirective(Node *n) {
String *modname = Getattr(n, "module");
if (modname) {
Printf(f_init, "pike_require(\"%s\");\n", modname);
}
return Language::importDirective(n);
}
/* ------------------------------------------------------------
* strip()
*
* For names that begin with the current class prefix plus an
* underscore (e.g. "Foo_enum_test"), return the base function
* name (i.e. "enum_test").
* ------------------------------------------------------------ */
String *strip(const DOHconst_String_or_char_ptr name) {
String *s = Copy(name);
if (Strncmp(name, PrefixPlusUnderscore, Len(PrefixPlusUnderscore)) != 0) {
return s;
}
Replaceall(s, PrefixPlusUnderscore, "");
return s;
}
/* ------------------------------------------------------------
* add_method()
* ------------------------------------------------------------ */
void add_method(const DOHconst_String_or_char_ptr name, const DOHconst_String_or_char_ptr function, const DOHconst_String_or_char_ptr 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: // shouldn't have gotten here for CLASS_CONST nodes
default: // what is this?
assert(false);
}
Delete(rename);
}
/* ---------------------------------------------------------------------
* functionWrapper()
*
* Create a function declaration and register it with the interpreter.
* --------------------------------------------------------------------- */
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");
Parm *p;
String *tm;
int i;
String *overname = 0;
if (Getattr(n, "sym:overloaded")) {
overname = Getattr(n, "sym:overname");
} else {
if (!addSymbol(iname, n))
return SWIG_ERROR;
}
Wrapper *f = NewWrapper();
// Emit all of the local variables for holding arguments.
emit_parameter_variables(l, f);
/* Attach the standard typemaps */
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 */
// int offset = (current == MEMBER_VAR) ? 1 : 0;
int offset = 0;
String *wname = Swig_name_wrapper(iname);
if (overname) {
Append(wname, overname);
}
Setattr(n, "wrap:name", wname);
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");
}
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);
Delete(lstr);
} 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);
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");
if (pikedesc) {
Printv(description, pikedesc, " ", NIL);
}
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));
break;
}
}
p = nextSibling(p);
}
/* Check for trailing varargs */
if (varargs) {
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");
} 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");
} else {
p = nextSibling(p);
}
}
/* 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");
} else {
p = nextSibling(p);
}
}
/* Emit the function call */
String *actioncode = emit_action(n);
/* Clear the return stack */
Printf(actioncode, "pop_n_elems(args);\n");
/* Return the function value */
if (current == CONSTRUCTOR) {
Printv(actioncode, "THIS = (void *) ", Swig_cresult_name(), ";\n", NIL);
Printv(description, ", tVoid", NIL);
} else if (current == DESTRUCTOR) {
Printv(description, ", tVoid", NIL);
} else {
Printv(description, ", ", NIL);
if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) {
actioncode = 0;
Replaceall(tm, "$source", Swig_cresult_name());
Replaceall(tm, "$target", "resultobj");
Replaceall(tm, "$result", "resultobj");
if (GetFlag(n, "feature:new")) {
Replaceall(tm, "$owner", "1");
} else {
Replaceall(tm, "$owner", "0");
}
String *pikedesc = Getattr(n, "tmap:out:pikedesc");
if (pikedesc) {
Printv(description, pikedesc, NIL);
}
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);
}
}
if (actioncode) {
Append(f->code, actioncode);
Delete(actioncode);
}
emit_return_variable(n, d, f);
/* Output argument output code */
Printv(f->code, outarg, NIL);
/* Output cleanup code */
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("newfree", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
}
}
/* See if there is any return cleanup code */
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
}
/* Close the function */
Printf(f->code, "}\n");
/* Substitute the cleanup code */
Replaceall(f->code, "$cleanup", cleanup);
/* Substitute the function name */
Replaceall(f->code, "$symname", iname);
Replaceall(f->code, "$result", "resultobj");
/* Dump the function out */
Wrapper_print(f, f_wrappers);
/* Now register the function with the interpreter. */
if (!Getattr(n, "sym:overloaded")) {
add_method(iname, wname, description);
} else {
if (!Getattr(n, "sym:nextSibling")) {
dispatchFunction(n);
}
}
Delete(cleanup);
Delete(outarg);
Delete(description);
Delete(wname);
DelWrapper(f);
return SWIG_OK;
}
/* ------------------------------------------------------------
* dispatchFunction()
*
* Emit overloading dispatch function
* ------------------------------------------------------------ */
void dispatchFunction(Node *n) {
/* Last node in overloaded chain */
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);
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) {
Printf(description, " tVoid");
} else {
String *pd = Getattr(n, "tmap:out:pikedesc");
if (pd)
Printf(description, " %s", pd);
}
add_method(symname, wname, description);
Delete(description);
DelWrapper(f);
Delete(dispatch);
Delete(tmp);
Delete(wname);
}
/* ------------------------------------------------------------
* variableWrapper()
* ------------------------------------------------------------ */
virtual int variableWrapper(Node *n) {
return Language::variableWrapper(n);
}
/* ------------------------------------------------------------
* constantWrapper()
* ------------------------------------------------------------ */
virtual int constantWrapper(Node *n) {
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");
bool is_enum_item = (Cmp(nodeType(n), "enumitem") == 0);
if (SwigType_type(type) == T_MPOINTER) {
/* Special hook for member pointer */
String *wname = Swig_name_wrapper(symname);
Printf(f_header, "static %s = %s;\n", SwigType_str(type, wname), value);
value = wname;
} else if (SwigType_type(type) == T_CHAR && is_enum_item) {
type = NewSwigType(T_INT);
Setattr(n, "type", type);
}
/* Perform constant typemap substitution */
String *tm = Swig_typemap_lookup("constant", n, value, 0);
if (tm) {
Replaceall(tm, "$source", value);
Replaceall(tm, "$target", symname);
Replaceall(tm, "$symname", symname);
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_restore(n);
return SWIG_OK;
}
/* ------------------------------------------------------------
* nativeWrapper()
* ------------------------------------------------------------ */
virtual int nativeWrapper(Node *n) {
// return Language::nativeWrapper(n);
String *name = Getattr(n, "sym:name");
String *wrapname = Getattr(n, "wrap:name");
if (!addSymbol(wrapname, n))
return SWIG_ERROR;
add_method(name, wrapname, 0);
return SWIG_OK;
}
/* ------------------------------------------------------------
* enumDeclaration()
* ------------------------------------------------------------ */
virtual int enumDeclaration(Node *n) {
return Language::enumDeclaration(n);
}
/* ------------------------------------------------------------
* enumvalueDeclaration()
* ------------------------------------------------------------ */
virtual int enumvalueDeclaration(Node *n) {
return Language::enumvalueDeclaration(n);
}
/* ------------------------------------------------------------
* classDeclaration()
* ------------------------------------------------------------ */
virtual int classDeclaration(Node *n) {
return Language::classDeclaration(n);
}
/* ------------------------------------------------------------
* classHandler()
* ------------------------------------------------------------ */
virtual int classHandler(Node *n) {
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");
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);
Delete(basemangle);
Delete(basetype);
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);
}
*/
/* 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);
String *tm = SwigType_manglestr(tt);
Printf(f_init, "SWIG_TypeClientData(SWIGTYPE%s, (void *) pr);\n", tm);
Delete(tm);
Delete(tt);
Delete(PrefixPlusUnderscore);
PrefixPlusUnderscore = 0;
return SWIG_OK;
}
/* ------------------------------------------------------------
* memberfunctionHandler()
*
* Method for adding C++ member function
* ------------------------------------------------------------ */
virtual int memberfunctionHandler(Node *n) {
current = MEMBER_FUNC;
Language::memberfunctionHandler(n);
current = NO_CPP;
return SWIG_OK;
}
/* ------------------------------------------------------------
* constructorHandler()
*
* Method for adding C++ member constructor
* ------------------------------------------------------------ */
virtual int constructorHandler(Node *n) {
current = CONSTRUCTOR;
Language::constructorHandler(n);
current = NO_CPP;
return SWIG_OK;
}
/* ------------------------------------------------------------
* destructorHandler()
* ------------------------------------------------------------ */
virtual int destructorHandler(Node *n) {
current = DESTRUCTOR;
Language::destructorHandler(n);
current = NO_CPP;
return SWIG_OK;
}
/* ------------------------------------------------------------
* membervariableAccessors()
* ------------------------------------------------------------ */
void membervariableAccessors(List *membervariables) {
String *name;
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;
break;
}
i = Next(i);
}
/* Create a function to set the values of the (mutable) variables */
if (need_setter) {
Wrapper *wrapper = NewWrapper();
String *setter = Swig_name_member(NSPACE_TODO, getClassPrefix(), "`->=");
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")) {
name = Getattr(i.item, "name");
funcname = Swig_name_wrapper(Swig_name_set(NSPACE_TODO, Swig_name_member(NSPACE_TODO, getClassPrefix(), name)));
Printf(wrapper->code, "if (!strcmp(name, \"%s\")) {\n", name);
Printf(wrapper->code, "%s(args);\n", funcname);
Printf(wrapper->code, "return;\n");
Printf(wrapper->code, "}\n");
Delete(funcname);
}
i = Next(i);
}
/* Close the function */
Printf(wrapper->code, "pop_n_elems(args);\n");
Printf(wrapper->code, "}\n");
/* 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);
Delete(description);
/* Clean up */
Delete(wname);
Delete(setter);
DelWrapper(wrapper);
}
/* Create a function to get the values of the (mutable) variables */
Wrapper *wrapper = NewWrapper();
String *getter = Swig_name_member(NSPACE_TODO, getClassPrefix(), "`->");
String *wname = Swig_name_wrapper(getter);
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) {
name = Getattr(i.item, "name");
funcname = Swig_name_wrapper(Swig_name_get(NSPACE_TODO, Swig_name_member(NSPACE_TODO, getClassPrefix(), name)));
Printf(wrapper->code, "if (!strcmp(name, \"%s\")) {\n", name);
Printf(wrapper->code, "%s(args);\n", funcname);
Printf(wrapper->code, "return;\n");
Printf(wrapper->code, "}\n");
Delete(funcname);
i = Next(i);
}
/* Close the function */
Printf(wrapper->code, "pop_n_elems(args);\n");
Printf(wrapper->code, "}\n");
/* 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);
DelWrapper(wrapper);
}
/* ------------------------------------------------------------
* membervariableHandler()
* ------------------------------------------------------------ */
virtual int membervariableHandler(Node *n) {
List *membervariables = Getattr(getCurrentClass(), "membervariables");
if (!membervariables) {
membervariables = NewList();
Setattr(getCurrentClass(), "membervariables", membervariables);
}
Append(membervariables, n);
current = MEMBER_VAR;
Language::membervariableHandler(n);
current = NO_CPP;
return SWIG_OK;
}
/* -----------------------------------------------------------------------
* staticmemberfunctionHandler()
*
* Wrap a static C++ function
* ---------------------------------------------------------------------- */
virtual int staticmemberfunctionHandler(Node *n) {
current = STATIC_FUNC;
Language::staticmemberfunctionHandler(n);
current = NO_CPP;
return SWIG_OK;
}
/* ------------------------------------------------------------
* memberconstantHandler()
*
* Create a C++ constant
* ------------------------------------------------------------ */
virtual int memberconstantHandler(Node *n) {
current = CLASS_CONST;
constantWrapper(n);
current = NO_CPP;
return SWIG_OK;
}
/* ---------------------------------------------------------------------
* staticmembervariableHandler()
* --------------------------------------------------------------------- */
virtual int staticmembervariableHandler(Node *n) {
current = STATIC_VAR;
Language::staticmembervariableHandler(n);
current = NO_CPP;
return SWIG_OK;
}
};
/* -----------------------------------------------------------------------------
* swig_pike() - Instantiate module
* ----------------------------------------------------------------------------- */
static Language *new_swig_pike() {
return new PIKE();
}
extern "C" Language *swig_pike(void) {
return new_swig_pike();
}

View file

@ -73,8 +73,10 @@ static int py3 = 0;
/* C++ Support + Shadow Classes */
static int have_constructor;
static int have_repr;
static int have_constructor = 0;
static int have_repr = 0;
static bool have_builtin_static_member_method_callback = false;
static bool have_fast_proxy_static_member_method_callback = false;
static String *real_classname;
/* Thread Support */
@ -93,6 +95,7 @@ static int nortti = 0;
static int relativeimport = 0;
/* flags for the make_autodoc function */
namespace {
enum autodoc_t {
AUTODOC_CLASS,
AUTODOC_CTOR,
@ -103,7 +106,7 @@ enum autodoc_t {
AUTODOC_CONST,
AUTODOC_VAR
};
}
static const char *usage1 = "\
Python Options (available with -python)\n\
@ -313,7 +316,6 @@ public:
} else {
Swig_arg_error();
}
/* end added */
} else if (strcmp(argv[i], "-globals") == 0) {
if (argv[i + 1]) {
global_name = NewString(argv[i + 1]);
@ -444,6 +446,15 @@ public:
}
}
if (builtin && !shadow) {
Printf(stderr, "Incompatible options -builtin and -noproxy specified.\n");
SWIG_exit(EXIT_FAILURE);
}
if (fastproxy) {
Preprocessor_define("SWIGPYTHON_FASTPROXY", 0);
}
if (doxygen)
doxygenTranslator = new PyDocConverter(doxygen_translator_flags);
@ -611,6 +622,10 @@ public:
Printf(f_runtime, "#define SWIGPYTHON_BUILTIN\n");
}
if (fastproxy) {
Printf(f_runtime, "#define SWIGPYTHON_FASTPROXY\n");
}
Printf(f_runtime, "\n");
Printf(f_header, "#ifdef SWIG_TypeQuery\n");
@ -814,6 +829,10 @@ public:
Append(const_code, "{0, 0, 0, 0.0, 0, 0}};\n");
Printf(f_wrappers, "%s\n", const_code);
if (have_fast_proxy_static_member_method_callback)
Printf(f_init, " SWIG_Python_FixMethods(SwigMethods_proxydocs, swig_const_table, swig_types, swig_type_initial);\n\n");
initialize_threads(f_init);
Printf(f_init, "#if PY_VERSION_HEX >= 0x03000000\n");
@ -846,8 +865,13 @@ public:
Printv(f_shadow_py, "\n", f_shadow_begin, "\n", NIL);
Printv(f_shadow_py, "\nfrom sys import version_info as _swig_python_version_info\n", NULL);
Printv(f_shadow_py, "if _swig_python_version_info < (2, 7, 0):\n", NULL);
Printv(f_shadow_py, tab4, "raise RuntimeError(\"Python 2.7 or later required\")\n\n", NULL);
if (py3) {
Printv(f_shadow_py, "if _swig_python_version_info < (3, 0):\n", NULL);
Printv(f_shadow_py, tab4, "raise RuntimeError(\"Python 3.x or later required\")\n\n", NULL);
} else {
Printv(f_shadow_py, "if _swig_python_version_info < (2, 7, 0):\n", NULL);
Printv(f_shadow_py, tab4, "raise RuntimeError(\"Python 2.7 or later required\")\n\n", NULL);
}
if (Len(f_shadow_after_begin) > 0)
Printv(f_shadow_py, f_shadow_after_begin, "\n", NIL);
@ -905,15 +929,15 @@ public:
* as a replacement of new.instancemethod in Python 3.
* ------------------------------------------------------------ */
int add_pyinstancemethod_new() {
String *name = NewString("SWIG_PyInstanceMethod_New");
String *line = NewString("");
Printf(line, "\t { \"%s\", %s, METH_O, NULL},\n", name, name);
Append(methods, line);
if (fastproxy) {
if (!builtin && fastproxy) {
String *name = NewString("SWIG_PyInstanceMethod_New");
String *line = NewString("");
Printf(line, "\t { \"%s\", %s, METH_O, NULL},\n", name, name);
Append(methods, line);
Append(methods_proxydocs, line);
Delete(line);
Delete(name);
}
Delete(line);
Delete(name);
return 0;
}
@ -923,7 +947,7 @@ public:
* generated for static methods when using -fastproxy
* ------------------------------------------------------------ */
int add_pystaticmethod_new() {
if (fastproxy) {
if (!builtin && fastproxy) {
String *name = NewString("SWIG_PyStaticMethod_New");
String *line = NewString("");
Printf(line, "\t { \"%s\", %s, METH_O, NULL},\n", name, name);
@ -2250,7 +2274,7 @@ public:
return parms;
}
bool funcanno = py3 ? true : false;
bool funcanno = Equal(Getattr(n, "feature:python:annotations"), "c") ? true : false;
String *params = NewString("");
String *_params = make_autodocParmList(n, false, ((in_class || has_self_for_count)? 2 : 1), is_calling, funcanno);
@ -2366,8 +2390,8 @@ public:
if (ret)
ret = SwigType_str(ret, 0);
}
return (ret && py3) ? NewStringf(" -> \"%s\"", ret)
: NewString("");
bool funcanno = Equal(Getattr(n, "feature:python:annotations"), "c") ? true : false;
return (ret && funcanno) ? NewStringf(" -> \"%s\"", ret) : NewString("");
}
/* ------------------------------------------------------------
@ -2472,6 +2496,7 @@ public:
Printf(methods, "\"swig_ptr: %s\"", Getattr(n, "feature:callback:name"));
if (fastproxy) {
Printf(methods_proxydocs, "\"swig_ptr: %s\"", Getattr(n, "feature:callback:name"));
have_fast_proxy_static_member_method_callback = true;
}
} else {
Append(methods, "NULL");
@ -2527,6 +2552,11 @@ public:
const char *builtin_kwargs = builtin_ctor ? ", PyObject *kwargs" : "";
Printv(f->def, linkage, builtin_ctor ? "int " : "PyObject *", wname, "(PyObject *self, PyObject *args", builtin_kwargs, ") {", NIL);
if (builtin) {
/* Avoid warning if the self parameter is not used. */
Append(f->code, "(void)self;\n");
}
Wrapper_add_local(f, "argc", "Py_ssize_t argc");
Printf(tmp, "PyObject *argv[%d] = {0}", maxargs + 1);
Wrapper_add_local(f, "argv", tmp);
@ -2696,7 +2726,6 @@ public:
bool add_self = builtin_self && (!builtin_ctor || director_class);
bool builtin_getter = (builtin && GetFlag(n, "memberget"));
bool builtin_setter = (builtin && GetFlag(n, "memberset") && !builtin_getter);
char const *self_param = builtin ? "self" : "SWIGUNUSEDPARM(self)";
char const *wrap_return = builtin_ctor ? "int " : "PyObject *";
String *linkage = NewString("SWIGINTERN ");
String *wrapper_name = Swig_name_wrapper(iname);
@ -2751,9 +2780,9 @@ public:
const char *builtin_kwargs = builtin_ctor ? ", PyObject *kwargs" : "";
if (!allow_kwargs || overname) {
if (!varargs) {
Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args", builtin_kwargs, ") {", NIL);
Printv(f->def, linkage, wrap_return, wname, "(PyObject *self, PyObject *args", builtin_kwargs, ") {", NIL);
} else {
Printv(f->def, linkage, wrap_return, wname, "__varargs__", "(PyObject *", self_param, ", PyObject *args, PyObject *varargs) {", NIL);
Printv(f->def, linkage, wrap_return, wname, "__varargs__", "(PyObject *self, PyObject *args, PyObject *varargs", builtin_kwargs, ") {", NIL);
}
if (allow_kwargs) {
Swig_warning(WARN_LANG_OVERLOAD_KEYWORD, input_file, line_number, "Can't use keyword arguments with overloaded functions (%s).\n", Swig_name_decl(n));
@ -2764,8 +2793,14 @@ public:
Swig_warning(WARN_LANG_VARARGS_KEYWORD, input_file, line_number, "Can't wrap varargs with keyword arguments enabled\n");
varargs = 0;
}
Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args, PyObject *kwargs) {", NIL);
Printv(f->def, linkage, wrap_return, wname, "(PyObject *self, PyObject *args, PyObject *kwargs) {", NIL);
}
if (builtin) {
/* Avoid warning if the self parameter is not used. */
Append(f->code, "(void)self;\n");
}
if (!builtin || !in_class || tuple_arguments > 0 || builtin_ctor) {
if (!allow_kwargs) {
Append(parse_args, " if (!PyArg_ParseTuple(args, \"");
@ -2792,7 +2827,7 @@ public:
/* Generate code for argument marshalling */
if (funpack) {
if (num_arguments > 0 && !overname) {
if (num_arguments > (builtin_self && !constructor ? 1 : 0) && !overname) {
sprintf(source, "PyObject *swig_obj[%d]", num_arguments);
Wrapper_add_localv(f, "swig_obj", source, NIL);
}
@ -2862,8 +2897,6 @@ public:
} 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 */
@ -2926,14 +2959,14 @@ public:
Clear(f->def);
if (overname) {
if (noargs) {
Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", Py_ssize_t nobjs, PyObject **SWIGUNUSEDPARM(swig_obj)) {", NIL);
Printv(f->def, linkage, wrap_return, wname, "(PyObject *self, Py_ssize_t nobjs, PyObject **SWIGUNUSEDPARM(swig_obj)) {", NIL);
} else {
Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", Py_ssize_t nobjs, PyObject **swig_obj) {", NIL);
Printv(f->def, linkage, wrap_return, wname, "(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) {", NIL);
}
Printf(parse_args, "if ((nobjs < %d) || (nobjs > %d)) SWIG_fail;\n", num_required, num_arguments);
} else {
int is_tp_call = Equal(Getattr(n, "feature:python:slot"), "tp_call");
Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args", builtin_kwargs, ") {", NIL);
Printv(f->def, linkage, wrap_return, wname, "(PyObject *self, PyObject *args", builtin_kwargs, ") {", NIL);
if (builtin_ctor)
Printf(parse_args, "if (!SWIG_Python_CheckNoKeywords(kwargs, \"%s\")) SWIG_fail;\n", iname);
if (onearg && !builtin_ctor && !is_tp_call) {
@ -2971,7 +3004,6 @@ public:
/* 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 {
@ -2993,7 +3025,6 @@ public:
}
}
if (tm && (Len(tm) != 0)) {
Replaceall(tm, "$source", Getattr(p, "lname"));
Printv(cleanup, tm, "\n", NIL);
}
p = Getattr(p, "tmap:freearg:next");
@ -3005,8 +3036,6 @@ 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);
@ -3095,8 +3124,6 @@ public:
} else {
Replaceall(tm, "$self", "obj0");
}
Replaceall(tm, "$source", Swig_cresult_name());
Replaceall(tm, "$target", "resultobj");
Replaceall(tm, "$result", "resultobj");
if (builtin_ctor) {
Replaceall(tm, "$owner", "SWIG_BUILTIN_INIT");
@ -3160,7 +3187,6 @@ public:
/* Look to see if there is any newfree cleanup code */
if (GetFlag(n, "feature:new")) {
if ((tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
Delete(tm);
}
@ -3168,7 +3194,6 @@ public:
/* See if there is any return cleanup code */
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
Delete(tm);
}
@ -3231,9 +3256,9 @@ public:
f = NewWrapper();
if (funpack) {
// Note: funpack is currently always false for varargs
Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", Py_ssize_t nobjs, PyObject **swig_obj) {", NIL);
Printv(f->def, linkage, wrap_return, wname, "(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) {", NIL);
} else {
Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args", builtin_kwargs, ") {", NIL);
Printv(f->def, linkage, wrap_return, wname, "(PyObject *self, PyObject *args", builtin_kwargs, ") {", NIL);
}
Wrapper_add_local(f, "resultobj", builtin_ctor ? "int resultobj" : "PyObject *resultobj");
Wrapper_add_local(f, "varargs", "PyObject *varargs");
@ -3251,10 +3276,10 @@ public:
Printf(f->code, " Py_XINCREF(swig_obj[i + %d]);\n", num_fixed_arguments);
Printf(f->code, "}\n");
} else {
Printf(f->code, "newargs = PyTuple_GetSlice(args,0,%d);\n", num_fixed_arguments);
Printf(f->code, "varargs = PyTuple_GetSlice(args,%d,PyTuple_Size(args));\n", num_fixed_arguments);
Printf(f->code, "newargs = PyTuple_GetSlice(args, 0, %d);\n", num_fixed_arguments);
Printf(f->code, "varargs = PyTuple_GetSlice(args, %d, PyTuple_Size(args));\n", num_fixed_arguments);
}
Printf(f->code, "resultobj = %s__varargs__(%s,newargs,varargs);\n", wname, builtin ? "self" : "NULL");
Printf(f->code, "resultobj = %s__varargs__(%s, newargs, varargs%s);\n", wname, builtin ? "self" : "NULL", strlen(builtin_kwargs) == 0 ? "" : ", kwargs");
Append(f->code, "Py_XDECREF(newargs);\n");
Append(f->code, "Py_XDECREF(varargs);\n");
Append(f->code, "return resultobj;\n");
@ -3426,7 +3451,6 @@ public:
Printf(f_init, "#endif\n");
Printf(f_init, "\t }\n");
Printf(f_init, "\t PyDict_SetItemString(md, \"%s\", globals);\n", global_name);
Printf(f_init, "\t Py_DECREF(globals);\n");
if (builtin)
Printf(f_init, "\t SwigPyBuiltin_AddPublicSymbol(public_interface, \"%s\");\n", global_name);
have_globals = 1;
@ -3454,8 +3478,6 @@ public:
}
Printf(setf->def, "SWIGINTERN int %s(PyObject *_val) {", varsetname);
if ((tm = Swig_typemap_lookup("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));
@ -3496,8 +3518,6 @@ public:
Append(getf->code, " (void)self;\n");
}
if ((tm = Swig_typemap_lookup("varout", n, name, 0))) {
Replaceall(tm, "$source", name);
Replaceall(tm, "$target", "pyobj");
Replaceall(tm, "$result", "pyobj");
addfail = emit_action_code(n, getf->code, tm);
Delete(tm);
@ -3577,8 +3597,6 @@ public:
}
if ((tm = Swig_typemap_lookup("consttab", n, name, 0))) {
Replaceall(tm, "$source", value);
Replaceall(tm, "$target", name);
Replaceall(tm, "$value", value);
Printf(const_code, "%s,\n", tm);
Delete(tm);
@ -3593,8 +3611,6 @@ public:
}
if ((tm = Swig_typemap_lookup("constcode", n, name, 0))) {
Replaceall(tm, "$source", value);
Replaceall(tm, "$target", name);
Replaceall(tm, "$value", value);
if (needs_swigconstant(n) && !builtin && (shadow) && (!(shadow & PYSHADOW_MEMBER)) && (!in_class || !Getattr(n, "feature:python:callback"))) {
// Generate `*_swigconstant()` method which registers the new constant.
@ -3606,7 +3622,7 @@ public:
// class type (the SWIG_init() is called before shadow classes are
// defined and registered).
Printf(f_wrappers, "SWIGINTERN PyObject *%s_swigconstant(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", iname);
Printf(f_wrappers, tab2 "PyObject *module;\n", tm);
Printf(f_wrappers, tab2 "PyObject *module;\n");
Printf(f_wrappers, tab2 "PyObject *d;\n");
Printf(f_wrappers, tab2 "if (!SWIG_Python_UnpackTuple(args, \"swigconstant\", 1, 1, &module)) return NULL;\n");
Printf(f_wrappers, tab2 "d = PyModule_GetDict(module);\n");
@ -3946,6 +3962,10 @@ public:
int funpack = fastunpack;
static String *tp_new = NewString("PyType_GenericNew");
if (have_builtin_static_member_method_callback) {
Printf(f_init, " SWIG_Python_FixMethods(SwigPyBuiltin_%s_methods, swig_const_table, swig_types, swig_type_initial);\n", mname);
}
Printv(f_init, " SwigPyBuiltin_SetMetaType(builtin_pytype, metatype);\n", NIL);
// We cant statically initialize a structure member with a function defined in another C module
@ -4016,7 +4036,7 @@ public:
if (GetFlag(mgetset, "static")) {
Printf(f, "static PyGetSetDef %s_def = %s;\n", gspair, entry);
Printf(f_init, "static_getset = SwigPyStaticVar_new_getset(metatype, &%s_def);\n", gspair);
Printf(f_init, "PyDict_SetItemString(d, static_getset->d_getset->name, (PyObject *) static_getset);\n", memname);
Printf(f_init, "PyDict_SetItemString(d, static_getset->d_getset->name, (PyObject *) static_getset);\n");
Printf(f_init, "Py_DECREF(static_getset);\n");
} else {
Printf(getset_def, " %s,\n", entry);
@ -4306,6 +4326,10 @@ public:
// struct _dictkeysobject *ht_cached_keys;
printSlot(f, getSlot(n, "feature:python:ht_cached_keys"), "ht_cached_keys");
Printv(f, "#endif\n", NIL);
Printv(f, "#if PY_VERSION_HEX >= 0x03090000\n", NIL);
printSlot(f, getSlot(n, "feature:python:ht_module"), "ht_module", "PyObject *");
Printv(f, "#endif\n", NIL);
Printf(f, "};\n\n");
String *clientdata = NewString("");
@ -4372,6 +4396,7 @@ public:
/* Create new strings for building up a wrapper function */
have_constructor = 0;
have_repr = 0;
have_builtin_static_member_method_callback = false;
class_name = Getattr(n, "sym:name");
real_classname = Getattr(n, "name");
@ -4461,7 +4486,9 @@ public:
Printf(f_shadow, "(Exception)");
} else {
Printf(f_shadow, "(object");
Printf(f_shadow, py3 && GetFlag(n, "feature:python:nondynamic") ? ", metaclass=_SwigNonDynamicMeta" : "", ")");
if (py3 && GetFlag(n, "feature:python:nondynamic")) {
Printf(f_shadow, ", metaclass=_SwigNonDynamicMeta");
}
Printf(f_shadow, ")");
}
}
@ -4732,6 +4759,7 @@ public:
Swig_restore(n);
}
int kw = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0;
if (builtin && in_class) {
if ((GetFlagAttr(n, "feature:extend") || checkAttribute(n, "access", "public"))
&& !Getattr(class_members, symname)) {
@ -4746,7 +4774,7 @@ public:
else if (funpack && argcount == 1)
Append(pyflags, "METH_O");
else
Append(pyflags, "METH_VARARGS");
Append(pyflags, kw ? "METH_VARARGS|METH_KEYWORDS" : "METH_VARARGS");
// Cast via void(*)(void) to suppress GCC -Wcast-function-type warning.
// Python should always call the function correctly, but the Python C
// API requires us to store it in function pointer of a different type.
@ -4754,6 +4782,11 @@ public:
String *ds = cdocstring(n, AUTODOC_STATICFUNC);
Printf(builtin_methods, " { \"%s\", (PyCFunction)(void(*)(void))%s, %s, \"%s\" },\n", symname, wname, pyflags, ds);
Delete(ds);
} else if (Getattr(n, "feature:callback")) {
String *ds = NewStringf("swig_ptr: %s", Getattr(n, "feature:callback:name"));
Printf(builtin_methods, " { \"%s\", (PyCFunction)(void(*)(void))%s, %s, \"%s\" },\n", symname, wname, pyflags, ds);
Delete(ds);
have_builtin_static_member_method_callback = true;
} else {
Printf(builtin_methods, " { \"%s\", (PyCFunction)(void(*)(void))%s, %s, \"\" },\n", symname, wname, pyflags);
}
@ -4772,7 +4805,6 @@ public:
String *staticfunc_name = NewString(fastproxy ? "_swig_new_static_method" : "staticmethod");
bool fast = (fastproxy && !have_addtofunc(n)) || Getattr(n, "feature:callback");
if (!fast || olddefs) {
int kw = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0;
String *parms = make_pyParmList(n, false, false, kw);
String *callParms = make_pyParmList(n, false, true, kw);
Printv(f_shadow, "\n", tab4, "@staticmethod", NIL);
@ -4869,6 +4901,7 @@ public:
String *classname = Swig_class_name(parent);
String *rclassname = Swig_class_name(getCurrentClass());
assert(rclassname);
(void)rclassname;
String *parms = make_pyParmList(n, true, false, allow_kwargs);
/* Pass 'self' only if using director */

View file

@ -634,7 +634,6 @@ String * R::createFunctionPointerHandler(SwigType *t, Node *n, int *numArgs) {
if(returnTM) {
String *tm = returnTM;
Replaceall(tm,"$input", "r_swig_cb_data->retValue");
Replaceall(tm,"$target", Swig_cresult_name());
replaceRClass(tm, rettype);
Replaceall(tm,"$owner", "0");
Replaceall(tm,"$disown","0");
@ -1302,13 +1301,14 @@ void R::addAccessor(String *memberName, Wrapper *wrapper, String *name,
#define MAX_OVERLOAD 256
namespace {
struct Overloaded {
Node *n; /* Node */
int argc; /* Argument count */
ParmList *parms; /* Parameters used for overload check */
int error; /* Ambiguity error */
};
}
List * R::Swig_overload_rank(Node *n,
bool script_lang_wrapping) {
@ -1745,7 +1745,7 @@ int R::functionWrapper(Node *n) {
/* Add the name of this member to a list for this class_name.
We will dump all these at the end. */
bool isSet(GetFlag(n, "memberset"));
bool isSet = GetFlag(n, "memberset") ? true : false;
String *tmp = NewString(isSet ? Swig_name_set(NSPACE_TODO, class_name) : Swig_name_get(NSPACE_TODO, class_name));
@ -1912,8 +1912,6 @@ int R::functionWrapper(Node *n) {
if ((tm = Getattr(p,"tmap:scheck"))) {
Replaceall(tm,"$target", lname);
Replaceall(tm,"$source", name);
Replaceall(tm,"$input", name);
replaceRClass(tm, Getattr(p, "type"));
Printf(sfun->code,"%s\n",tm);
@ -1924,8 +1922,6 @@ int R::functionWrapper(Node *n) {
curP = p;
if ((tm = Getattr(p,"tmap:in"))) {
Replaceall(tm,"$target", lname);
Replaceall(tm,"$source", name);
Replaceall(tm,"$input", name);
if (Getattr(p,"wrap:disown") || (Getattr(p,"tmap:in:disown"))) {
@ -1984,7 +1980,6 @@ int R::functionWrapper(Node *n) {
String *cleanup = NewString("");
for (p = l; p;) {
if ((tm = Getattr(p, "tmap:freearg"))) {
Replaceall(tm, "$source", Getattr(p, "lname"));
if (tm && (Len(tm) != 0)) {
Printv(cleanup, tm, "\n", NIL);
}
@ -2001,7 +1996,6 @@ int R::functionWrapper(Node *n) {
// String *lname = Getattr(p, "lname");
numOutArgs++;
String *pos = NewStringf("%d", numOutArgs);
Replaceall(tm,"$source", Getattr(p, "lname"));
Replaceall(tm,"$result", "r_ans");
Replaceall(tm,"$n", pos); // The position into which to store the answer.
Replaceall(tm,"$arg", Getattr(p, "emit:input"));
@ -2076,14 +2070,12 @@ int R::functionWrapper(Node *n) {
/* Look to see if there is any newfree cleanup code */
if (GetFlag(n, "feature:new")) {
if ((tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name()); /* deprecated */
Printf(f->code, "%s\n", tm);
}
}
/* See if there is any return cleanup code */
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
Delete(tm);
}
@ -2092,7 +2084,6 @@ int R::functionWrapper(Node *n) {
/*If the user gave us something to convert the result in */
if ((tm = Swig_typemap_lookup("scoerceout", n, Swig_cresult_name(), sfun))) {
Replaceall(tm,"$source","ans");
Replaceall(tm,"$result","ans");
if (constructor) {
Node * parent = Getattr(n, "parentNode");
@ -2578,7 +2569,7 @@ int R::generateCopyRoutines(Node *n) {
Printf(sfile, "# Start definition of copy methods for %s\n", rclassName);
Printf(sfile, "setMethod('copyToR', '_p_%s', CopyToR%s);\n", rclassName,
Printf(sfile, "setMethod('copyToR', '_p%s', CopyToR%s);\n", mangledName,
mangledName);
Printf(sfile, "setMethod('copyToC', '%s', CopyToC%s);\n\n", rclassName,
mangledName);

View file

@ -106,9 +106,10 @@ public:
char *strip(const_String_or_char_ptr s) {
Clear(temp);
Append(temp, s);
if (Strncmp(s, prefix, Len(prefix)) == 0) {
Replaceall(temp, prefix, "");
Append(temp, Char(s) + Len(prefix));
} else {
Append(temp, s);
}
return Char(temp);
}
@ -116,6 +117,7 @@ public:
/* flags for the make_autodoc function */
namespace {
enum autodoc_t {
AUTODOC_CLASS,
AUTODOC_CTOR,
@ -127,6 +129,7 @@ enum autodoc_t {
AUTODOC_SETTER,
AUTODOC_NONE
};
}
static const char *usage = "\
Ruby Options (available with -ruby)\n\
@ -1425,16 +1428,14 @@ public:
* applyInputTypemap()
*
* Look up the appropriate "in" typemap for this parameter (p),
* substitute the correct strings for the $target and $input typemap
* parameters, and dump the resulting code to the wrapper file.
* substitute the correct strings for the typemap parameters, and dump the
* resulting code to the wrapper file.
* --------------------------------------------------------------------- */
Parm *applyInputTypemap(Parm *p, String *ln, String *source, Wrapper *f, String *symname) {
Parm *applyInputTypemap(Parm *p, 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);
@ -1474,10 +1475,8 @@ public:
Parm *p;
String *tm;
String *source;
String *target;
source = NewString("");
target = NewString("");
bool ctor_director = (current == CONSTRUCTOR_INITIALIZE && Swig_directorclass(n));
@ -1498,7 +1497,6 @@ public:
p = skipIgnoredArgs(p);
String *pn = Getattr(p, "name");
String *ln = Getattr(p, "lname");
/* Produce string representation of source argument */
Clear(source);
@ -1510,10 +1508,6 @@ public:
Printf(source, "argv[%d]", i - start);
}
/* Produce string representation of target argument */
Clear(target);
Printf(target, "%s", Char(ln));
if (i >= (numreq)) { /* Check if parsing an optional argument */
Printf(f->code, " if (argc > %d) {\n", i - start);
}
@ -1526,7 +1520,7 @@ public:
}
/* Look for an input typemap */
p = applyInputTypemap(p, ln, source, f, Getattr(n, "name"));
p = applyInputTypemap(p, source, f, Getattr(n, "name"));
if (i >= numreq) {
Printf(f->code, "}\n");
}
@ -1553,7 +1547,6 @@ public:
}
Delete(source);
Delete(target);
}
/* ---------------------------------------------------------------------
@ -1569,7 +1562,6 @@ public:
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");
} else {
@ -1591,7 +1583,6 @@ public:
for (Parm *p = l; p;) {
if ((tm = Getattr(p, "tmap:freearg"))) {
if (Len(tm) != 0) {
Replaceall(tm, "$source", Getattr(p, "lname"));
Printv(cleanup, tm, "\n", NIL);
}
p = Getattr(p, "tmap:freearg:next");
@ -1613,8 +1604,6 @@ public:
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"));
@ -1876,8 +1865,6 @@ public:
actioncode = 0;
if (tm) {
Replaceall(tm, "$result", "vresult");
Replaceall(tm, "$source", Swig_cresult_name());
Replaceall(tm, "$target", "vresult");
if (GetFlag(n, "feature:new"))
Replaceall(tm, "$owner", "SWIG_POINTER_OWN");
@ -1973,7 +1960,6 @@ public:
if (current != CONSTRUCTOR_ALLOCATE && GetFlag(n, "feature:new")) {
tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0);
if (tm) {
Replaceall(tm, "$source", Swig_cresult_name());
Printv(f->code, tm, "\n", NIL);
Delete(tm);
}
@ -1982,7 +1968,6 @@ public:
/* Special processing on return value. */
tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0);
if (tm) {
Replaceall(tm, "$source", Swig_cresult_name());
Printv(f->code, tm, NIL);
Delete(tm);
}
@ -2212,8 +2197,6 @@ public:
tm = Swig_typemap_lookup("varout", n, name, 0);
if (tm) {
Replaceall(tm, "$result", "_val");
Replaceall(tm, "$target", "_val");
Replaceall(tm, "$source", name);
/* Printv(getf->code,tm, NIL); */
addfail = emit_action_code(n, getf->code, tm);
} else {
@ -2248,8 +2231,6 @@ public:
tm = Swig_typemap_lookup("varin", n, name, 0);
if (tm) {
Replaceall(tm, "$input", "_val");
Replaceall(tm, "$source", "_val");
Replaceall(tm, "$target", name);
/* Printv(setf->code,tm,"\n",NIL); */
emit_action_code(n, setf->code, tm);
} else {
@ -2361,8 +2342,6 @@ public:
if (!tm)
tm = Swig_typemap_lookup("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) {

View file

@ -1,402 +0,0 @@
/* -----------------------------------------------------------------------------
* This file is part of SWIG, which is licensed as a whole under version 3
* (or any later version) of the GNU General Public License. Some additional
* terms also apply to certain portions of SWIG. The full details of the SWIG
* license and copyrights can be found in the LICENSE and COPYRIGHT files
* included with the SWIG source code as distributed by the SWIG developers
* and at http://www.swig.org/legal.html.
*
* s-exp.cxx
*
* A parse tree represented as Lisp s-expressions.
* ----------------------------------------------------------------------------- */
#include "swigmod.h"
#include "dohint.h"
static const char *usage = "\
S-Exp Options (available with -sexp)\n\
-typemaplang <lang> - Typemap language\n\n";
//static Node *view_top = 0;
static File *out = 0;
class Sexp:public Language {
int indent_level;
DOHHash *print_circle_hash;
int print_circle_count;
int hanging_parens;
bool need_whitespace;
bool need_newline;
public:
Sexp():
indent_level(0),
print_circle_hash(0),
print_circle_count(0),
hanging_parens(0),
need_whitespace(0),
need_newline(0) {
}
virtual ~ Sexp() {
}
virtual void main(int argc, char *argv[]) {
// Add a symbol to the parser for conditional compilation
Preprocessor_define("SWIGSEXP 1", 0);
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);
}
}
}
/* 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", SWIG_output_files());
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("begin", f_sink);
Swig_register_filebyname("runtime", f_sink);
Swig_register_filebyname("init", f_sink);
Swig_banner_target_lang(out, ";;;");
Language::top(n);
Printf(out, "\n");
Printf(out, ";;; Lisp parse tree produced by SWIG\n");
print_circle_hash = NewHash();
print_circle_count = 0;
hanging_parens = 0;
need_whitespace = 0;
need_newline = 0;
Sexp_print_node(n);
flush_parens();
return SWIG_OK;
}
void print_indent() {
int i;
for (i = 0; i < indent_level; i++) {
Printf(out, " ");
}
}
void open_paren(const String *oper) {
flush_parens();
Printf(out, "(");
if (oper)
Printf(out, "%s ", oper);
indent_level += 2;
}
void close_paren(bool neednewline = false) {
hanging_parens++;
if (neednewline)
print_lazy_whitespace();
indent_level -= 2;
}
void flush_parens() {
int i;
if (hanging_parens) {
for (i = 0; i < hanging_parens; i++)
Printf(out, ")");
hanging_parens = 0;
need_newline = true;
need_whitespace = true;
}
if (need_newline) {
Printf(out, "\n");
print_indent();
need_newline = false;
need_whitespace = false;
} else if (need_whitespace) {
Printf(out, " ");
need_whitespace = false;
}
}
void print_lazy_whitespace() {
need_whitespace = 1;
}
void print_lazy_newline() {
need_newline = 1;
}
bool internal_key_p(DOH *key) {
return ((Cmp(key, "nodeType") == 0)
|| (Cmp(key, "firstChild") == 0)
|| (Cmp(key, "lastChild") == 0)
|| (Cmp(key, "parentNode") == 0)
|| (Cmp(key, "nextSibling") == 0)
|| (Cmp(key, "previousSibling") == 0)
|| (Cmp(key, "csym:nextSibling") == 0)
|| (Cmp(key, "csym:previousSibling") == 0)
|| (Cmp(key, "typepass:visit") == 0)
|| (Cmp(key, "allocate:visit") == 0)
|| (*(Char(key)) == '$'));
}
bool boolean_key_p(DOH *key) {
return ((Cmp(key, "allocate:default_constructor") == 0)
|| (Cmp(key, "allocate:default_destructor") == 0)
|| (Cmp(key, "allows_typedef") == 0)
|| (Cmp(key, "feature:immutable") == 0));
}
bool list_key_p(DOH *key) {
return ((Cmp(key, "parms") == 0)
|| (Cmp(key, "baselist") == 0));
}
bool plist_key_p(DOH *key)
// true if KEY is the name of data that is a mapping from keys to
// values, which should be printed as a plist.
{
return ((Cmp(key, "typescope") == 0));
}
bool maybe_plist_key_p(DOH *key) {
return (Strncmp(key, "tmap:", 5) == 0);
}
bool print_circle(DOH *obj, bool list_p)
// We have a complex object, which might be referenced several
// times, or even recursively. Use Lisp's reader notation for
// circular structures (#n#, #n=).
//
// An object can be printed in list-mode or object-mode; LIST_P toggles.
// return TRUE if OBJ still needs to be printed
{
flush_parens();
// Following is a silly hack. It works around the limitation of
// DOH's hash tables that only work with string keys!
char address[32];
sprintf(address, "%p%c", obj, list_p ? 'L' : 'O');
DOH *placeholder = Getattr(print_circle_hash, address);
if (placeholder) {
Printv(out, placeholder, NIL);
return false;
} else {
String *placeholder = NewStringf("#%d#", ++print_circle_count);
Setattr(print_circle_hash, address, placeholder);
Printf(out, "#%d=", print_circle_count);
return true;
}
}
void Sexp_print_value_of_key(DOH *value, DOH *key) {
if ((Cmp(key, "parms") == 0) || (Cmp(key, "wrap:parms") == 0)
|| (Cmp(key, "kwargs") == 0) || (Cmp(key, "pattern") == 0))
Sexp_print_parms(value);
else if (plist_key_p(key))
Sexp_print_plist(value);
else if (maybe_plist_key_p(key)) {
if (DohIsMapping(value))
Sexp_print_plist(value);
else
Sexp_print_doh(value);
} else if (list_key_p(key))
Sexp_print_list(value);
else if (boolean_key_p(key))
Sexp_print_boolean(value);
else
Sexp_print_doh(value);
}
void Sexp_print_boolean(DOH *obj) {
flush_parens();
/* See DOH/Doh/base.c, DohGetInt() */
if (DohIsString(obj)) {
if (atoi(Char(obj)) != 0)
Printf(out, "t");
else
Printf(out, "nil");
} else
Printf(out, "nil");
}
void Sexp_print_list(DOH *obj) {
if (print_circle(obj, true)) {
open_paren(NIL);
for (; obj; obj = nextSibling(obj)) {
Sexp_print_doh(obj);
print_lazy_whitespace();
}
close_paren(true);
}
}
void Sexp_print_parms(DOH *obj) {
// print it as a list of plists
if (print_circle(obj, true)) {
open_paren(NIL);
for (; obj; obj = nextSibling(obj)) {
if (DohIsMapping(obj)) {
Iterator k;
open_paren(NIL);
for (k = First(obj); k.key; k = Next(k)) {
if (!internal_key_p(k.key)) {
DOH *value = Getattr(obj, k.key);
Sexp_print_as_keyword(k.key);
Sexp_print_value_of_key(value, k.key);
print_lazy_whitespace();
}
}
close_paren(true);
} else
Sexp_print_doh(obj);
print_lazy_whitespace();
}
close_paren(true);
}
}
void Sexp_print_doh(DOH *obj) {
flush_parens();
if (DohIsString(obj)) {
String *o = Str(obj);
Replaceall(o, "\\", "\\\\");
Replaceall(o, "\"", "\\\"");
Printf(out, "\"%s\"", o);
Delete(o);
} else {
if (print_circle(obj, false)) {
// Dispatch type
if (nodeType(obj)) {
Sexp_print_node(obj);
}
else if (DohIsMapping(obj)) {
Iterator k;
open_paren(NIL);
for (k = First(obj); k.key; k = Next(k)) {
if (!internal_key_p(k.key)) {
DOH *value = Getattr(obj, k.key);
flush_parens();
open_paren(NIL);
Sexp_print_doh(k.key);
Printf(out, " . ");
Sexp_print_value_of_key(value, k.key);
close_paren();
}
}
close_paren();
} else if (strcmp(ObjType(obj)->objname, "List") == 0) {
int i;
open_paren(NIL);
for (i = 0; i < Len(obj); i++) {
DOH *item = Getitem(obj, i);
Sexp_print_doh(item);
}
close_paren();
} else {
// What is it?
Printf(out, "#<DOH %s %p>", ObjType(obj)->objname, obj);
}
}
}
}
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);
Delete(key);
}
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) {
if (!internal_key_p(k.key)) {
DOH *value = Getattr(obj, k.key);
flush_parens();
if (!first) {
Printf(out, " ");
}
Sexp_print_as_keyword(k.key);
/* Print value */
Sexp_print_value_of_key(value, k.key);
}
}
}
void Sexp_print_plist(DOH *obj) {
flush_parens();
if (print_circle(obj, true)) {
open_paren(NIL);
Sexp_print_plist_noparens(obj);
close_paren();
}
}
void Sexp_print_attributes(Node *obj) {
Sexp_print_plist_noparens(obj);
}
void Sexp_print_node(Node *obj) {
Node *cobj;
open_paren(nodeType(obj));
/* A node has an attribute list... */
Sexp_print_attributes(obj);
/* ... and child nodes. */
cobj = firstChild(obj);
if (cobj) {
print_lazy_newline();
flush_parens();
Sexp_print_as_keyword("children");
open_paren(NIL);
for (; cobj; cobj = nextSibling(cobj)) {
Sexp_print_node(cobj);
}
close_paren();
}
close_paren();
}
virtual int functionWrapper(Node *n) {
ParmList *l = Getattr(n, "parms");
Wrapper *f = NewWrapper();
emit_attach_parmmaps(l, f);
Setattr(n, "wrap:parms", l);
DelWrapper(f);
return SWIG_OK;
}
};
static Language *new_swig_sexp() {
return new Sexp();
}
extern "C" Language *swig_sexp(void) {
return new_swig_sexp();
}

View file

@ -11,10 +11,11 @@
* Scilab language module for SWIG.
* --------------------------------------------------------------------------*/
#include <cstddef>
#include <cstdlib>
#include "swigmod.h"
static const int SCILAB_IDENTIFIER_NAME_CHAR_MAX = 24;
static const int SCILAB_VARIABLE_NAME_CHAR_MAX = SCILAB_IDENTIFIER_NAME_CHAR_MAX - 4;
static const char *usage = (char *) " \
Scilab options (available with -scilab)\n \
@ -25,7 +26,6 @@ Scilab options (available with -scilab)\n \
-buildersources <files> - Add the (comma separated) files <files> to the builder sources\n \
-builderverbositylevel <level> - Set the builder verbosity level to <level> (default 0: off, 2: high)\n \
-gatewayxml <gateway_id> - Generate gateway xml with the given <gateway_id>\n \
-targetversion <scilab_major_version> - Generate for Scilab target (major) version (default: 5)\n \
\n";
@ -40,11 +40,11 @@ protected:
String *variablesCode;
int targetVersion;
bool generateBuilder;
File *builderFile;
String *builderCode;
String *builderCode5;
String *builderCode6;
int builderFunctionCount;
List *sourceFileList;
@ -67,6 +67,9 @@ protected:
bool createLoader;
File *loaderFile;
String *loaderScript;
String *loaderScript5;
String *loaderScript6;
int loaderFunctionCount;
public:
/* ------------------------------------------------------------------------
@ -74,8 +77,6 @@ public:
* ----------------------------------------------------------------------*/
virtual void main(int argc, char *argv[]) {
targetVersion = 5;
generateBuilder = false;
sourceFileList = NewList();
cflags = NewList();
@ -99,23 +100,23 @@ public:
/* Manage command line arguments */
for (int argIndex = 1; argIndex < argc; argIndex++) {
if (argv[argIndex] != NULL) {
if (strcmp(argv[argIndex], "-help") == 0) {
Printf(stdout, "%s\n", usage);
} else if (strcmp(argv[argIndex], "-builder") == 0) {
Swig_mark_arg(argIndex);
generateBuilder = true;
createLoader = false;
} else if (strcmp(argv[argIndex], "-buildersources") == 0) {
if (argv[argIndex + 1] != NULL) {
Swig_mark_arg(argIndex);
char *sourceFile = strtok(argv[argIndex + 1], ",");
while (sourceFile != NULL) {
Insert(sourceFileList, Len(sourceFileList), sourceFile);
sourceFile = strtok(NULL, ",");
}
Swig_mark_arg(argIndex + 1);
}
} else if (strcmp(argv[argIndex], "-buildercflags") == 0) {
if (strcmp(argv[argIndex], "-help") == 0) {
Printf(stdout, "%s\n", usage);
} else if (strcmp(argv[argIndex], "-builder") == 0) {
Swig_mark_arg(argIndex);
generateBuilder = true;
createLoader = false;
} else if (strcmp(argv[argIndex], "-buildersources") == 0) {
if (argv[argIndex + 1] != NULL) {
Swig_mark_arg(argIndex);
char *sourceFile = strtok(argv[argIndex + 1], ",");
while (sourceFile != NULL) {
Insert(sourceFileList, Len(sourceFileList), sourceFile);
sourceFile = strtok(NULL, ",");
}
Swig_mark_arg(argIndex + 1);
}
} else if (strcmp(argv[argIndex], "-buildercflags") == 0) {
Swig_mark_arg(argIndex);
if (argv[argIndex + 1] != NULL) {
Insert(cflags, Len(cflags), argv[argIndex + 1]);
@ -140,12 +141,6 @@ public:
createGatewayXML = true;
gatewayID = NewString(argv[argIndex + 1]);
Swig_mark_arg(argIndex + 1);
} else if (strcmp(argv[argIndex], "-targetversion") == 0) {
if (argv[argIndex + 1] != NULL) {
Swig_mark_arg(argIndex);
targetVersion = atoi(argv[argIndex + 1]);
Swig_mark_arg(argIndex + 1);
}
}
}
}
@ -227,10 +222,13 @@ public:
}
// Module initialization function
String *smallFunctionName = createSmallIdentifierName(gatewayName, SCILAB_IDENTIFIER_NAME_CHAR_MAX - 5);
String *gatewayInitFunctionName = NewStringf("%s_Init", gatewayName);
String *gatewayInitSmallFunctionName = NewStringf("%s_Init", smallFunctionName);
String *wrapperFunctionName = NewStringf("SWIG_%s_Init", gatewayName);
/* Add initialization function to builder table */
addFunctionToScilab(gatewayInitFunctionName, gatewayInitFunctionName);
addFunctionToScilab(gatewayInitFunctionName, gatewayInitSmallFunctionName, wrapperFunctionName);
// Add helper functions to builder table
addHelperFunctions();
@ -316,6 +314,8 @@ public:
/* Get some useful attributes of this function */
String *functionName = Getattr(node, "sym:name");
String *smallFunctionName = createSmallIdentifierName(functionName);
SwigType *functionReturnType = Getattr(node, "type");
ParmList *functionParamsList = Getattr(node, "parms");
@ -360,7 +360,7 @@ public:
int maxInputArguments = emit_num_arguments(functionParamsList);
int minInputArguments = emit_num_required(functionParamsList);
int minOutputArguments = 0;
int maxOutputArguments = 0;
int maxOutputArguments = 1;
if (!emit_isvarargs(functionParamsList)) {
Printf(wrapper->code, "SWIG_CheckInputArgument(pvApiCtx, $mininputarguments, $maxinputarguments);\n");
@ -472,7 +472,6 @@ public:
String *tm;
if ((tm = Getattr(param, "tmap:freearg"))) {
if (tm && (Len(tm) != 0)) {
Replaceall(tm, "$source", Getattr(param, "lname"));
Printf(wrapper->code, "%s\n", tm);
}
param = Getattr(param, "tmap:freearg:next");
@ -484,7 +483,6 @@ public:
/* See if there is any return cleanup code */
String *tm;
if ((tm = Swig_typemap_lookup("ret", node, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(wrapper->code, "%s\n", tm);
Delete(tm);
}
@ -500,10 +498,12 @@ public:
Replaceall(wrapper->code, "$symname", functionName);
/* Set CheckInputArgument and CheckOutputArgument input arguments */
/* In Scilab there is always one output even if not defined */
if (minOutputArguments == 0) {
if (maxOutputArguments < 1) {
maxOutputArguments = 1;
}
if (minOutputArguments == 1) {
minOutputArguments = 0;
}
String *argnumber = NewString("");
Printf(argnumber, "%d", minInputArguments);
Replaceall(wrapper->code, "$mininputarguments", argnumber);
@ -523,16 +523,14 @@ public:
/* Dump the function out */
Wrapper_print(wrapper, wrappersSection);
String *scilabFunctionName = checkIdentifierName(functionName, SCILAB_IDENTIFIER_NAME_CHAR_MAX);
/* Update builder.sce contents */
if (isLastOverloaded) {
addFunctionToScilab(scilabFunctionName, wrapperName);
addFunctionToScilab(functionName, smallFunctionName, wrapperName);
dispatchFunction(node);
}
if (!isOverloaded) {
addFunctionToScilab(scilabFunctionName, wrapperName);
addFunctionToScilab(functionName, smallFunctionName, wrapperName);
}
/* tidy up */
@ -593,21 +591,20 @@ public:
/* Get information about variable */
String *origVariableName = Getattr(node, "name"); // Ex: Shape::nshapes
String *variableName = Getattr(node, "sym:name"); // Ex; Shape_nshapes (can be used for function names, ...)
// Variable names can have SCILAB_VARIABLE_NAME_CHAR_MAX because of suffixes "_get" or "_set" added to function
String *scilabVariableName = checkIdentifierName(variableName, SCILAB_VARIABLE_NAME_CHAR_MAX);
String *smallVariableName = createSmallIdentifierName(variableName, SCILAB_IDENTIFIER_NAME_CHAR_MAX - 4);
/* Manage GET function */
Wrapper *getFunctionWrapper = NewWrapper();
String *getFunctionName = Swig_name_get(NSPACE_TODO, variableName);
String *scilabGetFunctionName = Swig_name_get(NSPACE_TODO, scilabVariableName);
String *scilabGetFunctionName = Swig_name_get(NSPACE_TODO, variableName);
String *scilabGetSmallFunctionName = Swig_name_get(NSPACE_TODO, smallVariableName);
Setattr(node, "wrap:name", getFunctionName);
Printv(getFunctionWrapper->def, "int ", getFunctionName, "(SWIG_GatewayParameters) {\n", NIL);
/* Check the number of input and output */
Printf(getFunctionWrapper->def, "SWIG_CheckInputArgument(pvApiCtx, 0, 0);\n");
Printf(getFunctionWrapper->def, "SWIG_CheckOutputArgument(pvApiCtx, 1, 1);\n");
Printf(getFunctionWrapper->def, "SWIG_CheckOutputArgument(pvApiCtx, 0, 1);\n");
Printf(getFunctionWrapper->def, "SWIG_Scilab_SetApiContext(pvApiCtx);\n");
String *varoutTypemap = Swig_typemap_lookup("varout", node, origVariableName, 0);
@ -623,20 +620,21 @@ public:
Wrapper_print(getFunctionWrapper, wrappersSection);
/* Add function to builder table */
addFunctionToScilab(scilabGetFunctionName, getFunctionName);
addFunctionToScilab(scilabGetFunctionName, scilabGetSmallFunctionName, getFunctionName);
/* Manage SET function */
if (is_assignable(node)) {
Wrapper *setFunctionWrapper = NewWrapper();
String *setFunctionName = Swig_name_set(NSPACE_TODO, variableName);
String *scilabSetFunctionName = Swig_name_set(NSPACE_TODO, scilabVariableName);
String *scilabSetFunctionName = Swig_name_set(NSPACE_TODO, variableName);
String *scilabSetSmallFunctionName = Swig_name_set(NSPACE_TODO, smallVariableName);
Setattr(node, "wrap:name", setFunctionName);
Printv(setFunctionWrapper->def, "int ", setFunctionName, "(SWIG_GatewayParameters) {\n", NIL);
/* Check the number of input and output */
Printf(setFunctionWrapper->def, "SWIG_CheckInputArgument(pvApiCtx, 1, 1);\n");
Printf(setFunctionWrapper->def, "SWIG_CheckOutputArgument(pvApiCtx, 1, 1);\n");
Printf(setFunctionWrapper->def, "SWIG_CheckOutputArgument(pvApiCtx, 0, 1);\n");
Printf(setFunctionWrapper->def, "SWIG_Scilab_SetApiContext(pvApiCtx);\n");
String *varinTypemap = Swig_typemap_lookup("varin", node, origVariableName, 0);
@ -650,7 +648,7 @@ public:
Wrapper_print(setFunctionWrapper, wrappersSection);
/* Add function to builder table */
addFunctionToScilab(scilabSetFunctionName, setFunctionName);
addFunctionToScilab(scilabSetFunctionName, scilabSetSmallFunctionName, setFunctionName);
DelWrapper(setFunctionWrapper);
}
@ -686,10 +684,9 @@ public:
constantTypemap = Swig_typemap_lookup("scilabconstcode", node, nodeName, 0);
if (constantTypemap != NULL) {
String *scilabConstantName = checkIdentifierName(constantName, SCILAB_IDENTIFIER_NAME_CHAR_MAX);
Setattr(node, "wrap:name", constantName);
Replaceall(constantTypemap, "$result", scilabConstantName);
Replaceall(constantTypemap, "$result", constantName);
Replaceall(constantTypemap, "$value", constantValue);
emit_action_code(node, variablesCode, constantTypemap);
@ -707,19 +704,21 @@ public:
Delete(str);
constantValue = wname;
}
// Constant names can have SCILAB_VARIABLE_NAME_CHAR_MAX because of suffixes "_get" added to function
String *scilabConstantName = checkIdentifierName(constantName, SCILAB_VARIABLE_NAME_CHAR_MAX);
String *smallConstantName = createSmallIdentifierName(constantName, SCILAB_IDENTIFIER_NAME_CHAR_MAX - 4);
/* Create GET function to get the constant value */
Wrapper *getFunctionWrapper = NewWrapper();
String *getFunctionName = Swig_name_get(NSPACE_TODO, constantName);
String *scilabGetFunctionName = Swig_name_get(NSPACE_TODO, scilabConstantName);
String *scilabGetSmallFunctionName = Swig_name_get(NSPACE_TODO, smallConstantName);
Setattr(node, "wrap:name", getFunctionName);
Setattr(node, "wrap:name", getFunctionName);
Printv(getFunctionWrapper->def, "int ", getFunctionName, "(SWIG_GatewayParameters) {\n", NIL);
/* Check the number of input and output */
Printf(getFunctionWrapper->def, "SWIG_CheckInputArgument(pvApiCtx, 0, 0);\n");
Printf(getFunctionWrapper->def, "SWIG_CheckOutputArgument(pvApiCtx, 1, 1);\n");
Printf(getFunctionWrapper->def, "SWIG_CheckOutputArgument(pvApiCtx, 0, 1);\n");
Printf(getFunctionWrapper->def, "SWIG_Scilab_SetApiContext(pvApiCtx);\n");
constantTypemap = Swig_typemap_lookup("constcode", node, nodeName, 0);
@ -737,7 +736,7 @@ public:
Wrapper_print(getFunctionWrapper, wrappersSection);
/* Add the function to Scilab */
addFunctionToScilab(scilabGetFunctionName, getFunctionName);
addFunctionToScilab(getFunctionName, scilabGetSmallFunctionName, getFunctionName);
DelWrapper(getFunctionWrapper);
@ -784,78 +783,13 @@ public:
return Language::enumvalueDeclaration(node);
}
/* ---------------------------------------------------------------------
* membervariableHandler()
* --------------------------------------------------------------------- */
virtual int membervariableHandler(Node *node) {
checkMemberIdentifierName(node, SCILAB_VARIABLE_NAME_CHAR_MAX);
return Language::membervariableHandler(node);
}
/* -----------------------------------------------------------------------
* checkIdentifierName()
* If Scilab target version is lower than 6:
* truncates (and displays a warning) too long member identifier names
* (applies on members of structs, classes...)
* (Scilab 5 identifier names are limited to 24 chars max)
* ----------------------------------------------------------------------- */
String *checkIdentifierName(String *name, int char_size_max) {
String *scilabIdentifierName;
if (targetVersion <= 5) {
if (Len(name) > char_size_max) {
scilabIdentifierName = DohNewStringWithSize(name, char_size_max);
Swig_warning(WARN_SCILAB_TRUNCATED_NAME, input_file, line_number,
"Identifier name '%s' exceeds 24 characters and has been truncated to '%s'.\n", name, scilabIdentifierName);
} else
scilabIdentifierName = name;
} else {
scilabIdentifierName = DohNewString(name);
}
return scilabIdentifierName;
}
/* -----------------------------------------------------------------------
* checkMemberIdentifierName()
* If Scilab target version is lower than 6:
* truncates (and displays a warning) too long member identifier names
* (applies on members of structs, classes...)
* (Scilab 5 identifier names are limited to 24 chars max)
* ----------------------------------------------------------------------- */
void checkMemberIdentifierName(Node *node, int char_size_max) {
if (targetVersion <= 5) {
String *memberName = Getattr(node, "sym:name");
Node *containerNode = parentNode(node);
String *containerName = Getattr(containerNode, "sym:name");
int lenContainerName = Len(containerName);
int lenMemberName = Len(memberName);
if (lenContainerName + lenMemberName + 1 > char_size_max) {
int lenScilabMemberName = char_size_max - lenContainerName - 1;
if (lenScilabMemberName > 0) {
String *scilabMemberName = DohNewStringWithSize(memberName, lenScilabMemberName);
Setattr(node, "sym:name", scilabMemberName);
Swig_warning(WARN_SCILAB_TRUNCATED_NAME, input_file, line_number,
"Wrapping functions names for member '%s.%s' will exceed 24 characters, "
"so member name has been truncated to '%s'.\n", containerName, memberName, scilabMemberName);
} else {
Swig_error(input_file, line_number,
"Wrapping functions names for member '%s.%s' will exceed 24 characters, "
"please rename the container of member '%s'.\n", containerName, memberName, containerName);
}
}
}
}
/* -----------------------------------------------------------------------
* addHelperFunctions()
* ----------------------------------------------------------------------- */
void addHelperFunctions() {
addFunctionToScilab("SWIG_this", "SWIG_this");
addFunctionToScilab("SWIG_ptr", "SWIG_ptr");
addFunctionToScilab("SWIG_this", "SWIG_this", "SWIG_this");
addFunctionToScilab("SWIG_ptr", "SWIG_ptr", "SWIG_ptr");
}
/* -----------------------------------------------------------------------
@ -863,20 +797,20 @@ public:
* Declare a wrapped function in Scilab (builder, gateway, XML, ...)
* ----------------------------------------------------------------------- */
void addFunctionToScilab(const_String_or_char_ptr scilabFunctionName, const_String_or_char_ptr wrapperFunctionName) {
void addFunctionToScilab(const_String_or_char_ptr scilabFunctionName, const_String_or_char_ptr scilabSmallFunctionName, const_String_or_char_ptr wrapperFunctionName) {
if (!generateBuilder)
addFunctionInGatewayHeader(scilabFunctionName, wrapperFunctionName);
addFunctionInGatewayHeader(scilabFunctionName, scilabSmallFunctionName, wrapperFunctionName);
if (generateBuilder) {
addFunctionInScriptTable(scilabFunctionName, wrapperFunctionName, builderCode);
addFunctionInScriptTable(scilabFunctionName, scilabSmallFunctionName, wrapperFunctionName, builderCode5, builderCode6);
}
if (createLoader) {
addFunctionInLoader(scilabFunctionName);
addFunctionInLoader(scilabFunctionName, scilabSmallFunctionName);
}
if (gatewayXMLFile) {
Printf(gatewayXML, "<PRIMITIVE gatewayId=\"%s\" primitiveId=\"%d\" primitiveName=\"%s\"/>\n", gatewayID, primitiveID++, scilabFunctionName);
Printf(gatewayXML, "<PRIMITIVE gatewayId=\"%s\" primitiveId=\"%d\" primitiveName=\"%s\"/>\n", gatewayID, primitiveID++, scilabSmallFunctionName);
}
}
@ -945,7 +879,8 @@ public:
}
}
Printf(builderCode, "table = [");
Printf(builderCode5, "table = [ ..\n");
Printf(builderCode6, "table = [ ..\n");
}
/* -----------------------------------------------------------------------
@ -953,11 +888,13 @@ public:
* Add a function wrapper in the function table of generated builder script
* ----------------------------------------------------------------------- */
void addFunctionInScriptTable(const_String_or_char_ptr scilabFunctionName, const_String_or_char_ptr wrapperFunctionName, String *scriptCode) {
void addFunctionInScriptTable(const_String_or_char_ptr scilabFunctionName, const_String_or_char_ptr scilabSmallFunctionName, const_String_or_char_ptr wrapperFunctionName, String *scriptCode5, String *scriptCode6) {
if (++builderFunctionCount % 10 == 0) {
Printf(scriptCode, "];\ntable = [table;");
Printf(scriptCode5, "];\ntable = [table; ..\n");
Printf(scriptCode6, "];\ntable = [table; ..\n");
}
Printf(scriptCode, "\"%s\",\"%s\";", scilabFunctionName, wrapperFunctionName);
Printf(scriptCode5, "\"%s\",\"%s\"; ..\n", scilabSmallFunctionName, wrapperFunctionName);
Printf(scriptCode6, "\"%s\",\"%s\"; ..\n", scilabFunctionName, wrapperFunctionName);
}
/* -----------------------------------------------------------------------
@ -965,7 +902,26 @@ public:
* ----------------------------------------------------------------------- */
void saveBuilderFile(String *gatewayName) {
Printf(builderCode, "];\n");
Printf(builderCode5, "];\n");
Printf(builderCode6, "];\n");
if (Equal(builderCode5, builderCode6)) {
Append(builderCode, builderCode6);
} else {
Printf(builderCode, "ver = getversion('scilab');\n");
Printf(builderCode, "if ver(1) < 6 then\n");
Printf(builderCode, " // version is less or equal to 5.5.2\n");
Printf(builderCode, " \n");
Append(builderCode, builderCode5);
Printf(builderCode, " \n");
Printf(builderCode, "else\n");
Printf(builderCode, " // version is 6.0.0 or more\n");
Printf(builderCode, " \n");
Append(builderCode, builderCode6);
Printf(builderCode, " \n");
Printf(builderCode, "end\n");
}
Printf(builderCode, "ierr = 0;\n");
Printf(builderCode, "if ~isempty(table) then\n");
Printf(builderCode, " ierr = execstr(\"ilib_build(''%s'', table, files, libs, [], ldflags, cflags);\", 'errcatch');\n", gatewayName);
@ -977,7 +933,9 @@ public:
Printf(builderCode, "if ierr <> 0 then\n");
Printf(builderCode, " error(ierr, err_msg);\n");
Printf(builderCode, "end\n");
Printv(builderFile, builderCode, NIL);
Write(builderFile, builderCode, Len(builderCode));
Delete(builderCode);
Delete(builderFile);
}
@ -1049,13 +1007,13 @@ public:
* Add a function in the gateway header
* ----------------------------------------------------------------------- */
void addFunctionInGatewayHeader(const_String_or_char_ptr scilabFunctionName, const_String_or_char_ptr wrapperFunctionName) {
void addFunctionInGatewayHeader(const_String_or_char_ptr scilabFunctionName, const_String_or_char_ptr scilabSmallFunctionName, const_String_or_char_ptr wrapperFunctionName) {
if (gatewayHeaderV5 == NULL) {
gatewayHeaderV5 = NewString("");
Printf(gatewayHeaderV5, "static GenericTable Tab[] = {\n");
} else
Printf(gatewayHeaderV5, ",\n");
Printf(gatewayHeaderV5, " {(Myinterfun)sci_gateway, (GT)%s, (char *)\"%s\"}", wrapperFunctionName, scilabFunctionName);
Printf(gatewayHeaderV5, " {(Myinterfun)sci_gateway, (GT)%s, (char *)\"%s\"}", wrapperFunctionName, scilabSmallFunctionName);
Printf(gatewayHeaderV6, "if (wcscmp(pwstFuncName, L\"%s\") == 0) { addCStackFunction((wchar_t *)L\"%s\", &%s, (wchar_t *)MODULE_NAME); }\n", scilabFunctionName, scilabFunctionName, wrapperFunctionName);
}
@ -1113,13 +1071,15 @@ public:
emitBanner(loaderFile);
loaderScript = NewString("");
Printf(loaderScript, "%s_path = get_absolute_file_path('loader.sce');\n", gatewayLibraryName);
Printf(loaderScript, "[bOK, ilib] = c_link('%s');\n", gatewayLibraryName);
Printf(loaderScript, "if bOK then\n");
Printf(loaderScript, " ulink(ilib);\n");
Printf(loaderScript, "end\n");
Printf(loaderScript, "list_functions = [..\n");
loaderFunctionCount = 0;
loaderScript = NewString("function loader_function()\n");
Printf(loaderScript, " p = get_absolute_file_path('loader.sce');\n", gatewayLibraryName);
Printf(loaderScript, " [bOK, ilib] = c_link('%s');\n", gatewayLibraryName);
Printf(loaderScript, " if bOK then\n");
Printf(loaderScript, " ulink(ilib);\n");
Printf(loaderScript, " end\n");
loaderScript5 = NewString(" list_functions = [ ..\n");
loaderScript6 = NewString(" list_functions = [ ..\n");
}
/* -----------------------------------------------------------------------
@ -1127,8 +1087,13 @@ public:
* Add a function in the loader script table
* ----------------------------------------------------------------------- */
void addFunctionInLoader(const_String_or_char_ptr scilabFunctionName) {
Printf(loaderScript, " '%s'; ..\n", scilabFunctionName);
void addFunctionInLoader(const_String_or_char_ptr scilabFunctionName, const_String_or_char_ptr scilabSmallFunctionName) {
if (++loaderFunctionCount % 10 == 0) {
Printf(loaderScript5, " ];\n list_functions = [list_functions; ..\n");
Printf(loaderScript6, " ];\n list_functions = [list_functions; ..\n");
}
Printf(loaderScript5, " '%s'; ..\n", scilabSmallFunctionName);
Printf(loaderScript6, " '%s'; ..\n", scilabFunctionName);
}
/* -----------------------------------------------------------------------
@ -1137,18 +1102,66 @@ public:
* ----------------------------------------------------------------------- */
void saveLoaderFile(String *gatewayLibraryName) {
Printf(loaderScript, "];\n");
Printf(loaderScript, "addinter(fullfile(%s_path, '%s' + getdynlibext()), '%s', list_functions);\n",
gatewayLibraryName, gatewayLibraryName, gatewayLibraryName);
Printf(loaderScript, "clear %s_path;\n", gatewayLibraryName);
Printf(loaderScript, "clear bOK;\n");
Printf(loaderScript, "clear ilib;\n");
Printf(loaderScript, "clear list_functions;\n");
Printf(loaderScript5, " ];\n");
Printf(loaderScript6, " ];\n");
if (Equal(loaderScript5, loaderScript6)) {
Append(loaderScript, loaderScript6);
} else {
Printf(loaderScript, " ver = getversion('scilab');\n");
Printf(loaderScript, " if ver(1) < 6 then\n");
Printf(loaderScript, " // version is less or equal to 5.5.2\n");
Printf(loaderScript, " \n");
Append(loaderScript, loaderScript5);
Delete(loaderScript5);
Printf(loaderScript, " \n");
Printf(loaderScript, " else\n");
Printf(loaderScript, " // version is 6.0.0 or more\n");
Printf(loaderScript, " \n");
Append(loaderScript, loaderScript6);
Delete(loaderScript6);
Printf(loaderScript, " \n");
Printf(loaderScript, " end\n");
}
Printf(loaderScript, " addinter(p + '%s' + getdynlibext(), '%s', list_functions);\n", gatewayLibraryName, gatewayLibraryName);
Printf(loaderScript, "endfunction\n");
Printf(loaderScript, "loader_function();\n");
Printf(loaderScript, "clear loader_function;\n");
Printv(loaderFile, loaderScript, NIL);
Delete(loaderScript);
Delete(loaderFile);
}
/* -----------------------------------------------------------------------
* createSmallIdentifierName()
* Create a Scilab small identifier to be used by Scilab 5
* ----------------------------------------------------------------------- */
String* createSmallIdentifierName(String* name, int outputLen = SCILAB_IDENTIFIER_NAME_CHAR_MAX) {
char* s = Char(name);
int nameLen = Len(s);
// truncate and preserve common suffix
if (outputLen > 4 && nameLen > outputLen) {
String* smallName = NewStringWithSize(name, outputLen);
char* smallNameStr = (char*) Data(smallName);
if (s[nameLen-4] == '_' && s[nameLen - 3] == 'g' && s[nameLen - 2] == 'e' && s[nameLen - 1] == 't') {
// get
memcpy(&smallNameStr[outputLen - 4], &s[nameLen - 4], 4);
} else if (s[nameLen-4] == '_' && s[nameLen - 3] == 's' && s[nameLen - 2] == 'e' && s[nameLen - 1] == 't') {
// set
memcpy(&smallNameStr[outputLen - 4], &s[nameLen - 4], 4);
}
return smallName;
}
return name;
}
};
extern "C" Language *swig_scilab(void) {

View file

@ -336,8 +336,6 @@ public:
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);
@ -401,7 +399,6 @@ public:
/* 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");
} else {
@ -414,7 +411,6 @@ public:
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);
}
p = Getattr(p, "tmap:freearg:next");
@ -426,12 +422,9 @@ public:
/* Insert argument output code */
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");
#else
Replaceall(tm, "$target", "(Tcl_GetObjResult(interp))");
Replaceall(tm, "$result", "(Tcl_GetObjResult(interp))");
#endif
Replaceall(tm, "$arg", Getattr(p, "emit:input"));
@ -450,12 +443,9 @@ public:
/* Return value if necessary */
if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) {
Replaceall(tm, "$source", Swig_cresult_name());
#ifdef SWIG_USE_RESULTOBJ
Replaceall(tm, "$target", "resultobj");
Replaceall(tm, "$result", "resultobj");
#else
Replaceall(tm, "$target", "(Tcl_GetObjResult(interp))");
Replaceall(tm, "$result", "(Tcl_GetObjResult(interp))");
#endif
if (GetFlag(n, "feature:new")) {
@ -478,13 +468,11 @@ public:
/* Look for any remaining cleanup */
if (GetFlag(n, "feature:new")) {
if ((tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
}
}
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
}
#ifdef SWIG_USE_RESULTOBJ
@ -580,8 +568,6 @@ public:
Printv(getf->def, "SWIGINTERN const char *", getfname, "(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("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->code, tm);
@ -616,8 +602,6 @@ public:
Wrapper_add_local(setf, "name1o", "Tcl_Obj *name1o = 0");
if ((tm = Swig_typemap_lookup("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");
@ -690,14 +674,10 @@ public:
}
if ((tm = Swig_typemap_lookup("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("constcode", n, name, 0))) {
Replaceall(tm, "$source", value);
Replaceall(tm, "$target", name);
Replaceall(tm, "$value", value);
Replaceall(tm, "$nsname", nsname);
Printf(f_init, "%s\n", tm);
@ -909,7 +889,7 @@ public:
// Add methods
if (have_methods) {
Printv(ptrclass, imethods, NIL);
};
}
// Close out the pointer class
Printv(ptrclass, "}\n\n", NIL);
@ -967,7 +947,7 @@ public:
if (!itcl) {
Printv(cmd_tab, tab4, "{ SWIG_prefix \"", class_name, "\", (swig_wrapper_func) SWIG_ObjectConstructor, (ClientData)&_wrap_class_", mangled_classname,
"},\n", NIL);
};
}
Delete(t);
Delete(mangled_classname);
@ -1043,7 +1023,7 @@ public:
Printv(imethods, "{ ", ns_name, "::", class_name, "_", realname, " $swigobj", NIL);
} else {
Printv(imethods, "{ ", class_name, "_", realname, " $swigobj", NIL);
};
}
pnum = 0;
for (p = l; p; p = nextSibling(p)) {

View file

@ -1047,13 +1047,6 @@ class TypePass:private Dispatcher {
|| (Getattr(c, "feature:extend") && !Getattr(c, "code"))
|| GetFlag(c, "feature:ignore"))) {
/* Don't generate a method if the method is overridden in this class,
* for example don't generate another m(bool) should there be a Base::m(bool) :
* struct Derived : Base {
* void m(bool);
* using Base::m;
* };
*/
String *csymname = Getattr(c, "sym:name");
if (!csymname || (Strcmp(csymname, symname) == 0)) {
{
@ -1069,11 +1062,20 @@ class TypePass:private Dispatcher {
over = Getattr(over, "sym:nextSibling");
}
if (match) {
/* Don't generate a method if the method is overridden in this class,
* for example don't generate another m(bool) should there be a Base::m(bool) :
* struct Derived : Base {
* void m(bool);
* using Base::m;
* };
*/
c = Getattr(c, "csym:nextSibling");
continue;
}
}
Node *nn = copyNode(c);
Setfile(nn, Getfile(n));
Setline(nn, Getline(n));
Delattr(nn, "access"); // access might be different from the method in the base class
Setattr(nn, "access", Getattr(n, "access"));
if (!Getattr(nn, "sym:name"))
@ -1117,6 +1119,9 @@ class TypePass:private Dispatcher {
} else {
Delete(nn);
}
} else {
Swig_warning(WARN_LANG_USING_NAME_DIFFERENT, Getfile(n), Getline(n), "Using declaration %s, with name '%s', is not actually using\n", SwigType_namestr(Getattr(n, "uname")), symname);
Swig_warning(WARN_LANG_USING_NAME_DIFFERENT, Getfile(c), Getline(c), "the method from %s, with name '%s', as the names are different.\n", Swig_name_decl(c), csymname);
}
}
}

View file

@ -1,405 +0,0 @@
/* -----------------------------------------------------------------------------
* This file is part of SWIG, which is licensed as a whole under version 3
* (or any later version) of the GNU General Public License. Some additional
* terms also apply to certain portions of SWIG. The full details of the SWIG
* license and copyrights can be found in the LICENSE and COPYRIGHT files
* included with the SWIG source code as distributed by the SWIG developers
* and at http://www.swig.org/legal.html.
*
* uffi.cxx
*
* Uffi language module for SWIG.
* ----------------------------------------------------------------------------- */
// TODO: remove remnants of lisptype
#include "swigmod.h"
static const char *usage = "\
UFFI Options (available with -uffi)\n\
-identifier-converter <type or funcname> - \n\
Specifies the type of conversion to do on C identifiers\n\
to convert them to symbols. There are two built-in\n\
converters: 'null' and 'lispify'. The default is\n\
'null'. If you supply a name other than one of the\n\
built-ins, then a function by that name will be\n\
called to convert identifiers to symbols.\n\
";
class UFFI:public Language {
public:
virtual void main(int argc, char *argv[]);
virtual int top(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 struct {
int count;
String **entries;
} defined_foreign_types;
static String *identifier_converter = NewString("identifier-convert-null");
static int any_varargs(ParmList *pl) {
Parm *p;
for (p = pl; p; p = nextSibling(p)) {
if (SwigType_isvarargs(Getattr(p, "type")))
return 1;
}
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;
}
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;
}
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 *));
} else {
/* make room */
defined_foreign_types.count++;
defined_foreign_types.entries = (String **)
realloc(defined_foreign_types.entries, defined_foreign_types.count * sizeof(String *));
}
if (!defined_foreign_types.entries) {
Printf(stderr, "Out of memory\n");
SWIG_exit(EXIT_FAILURE);
}
/* Fill in the new data */
defined_foreign_types.entries[defined_foreign_types.count - 1] = Copy(type);
}
static String *get_ffi_type(Node *n, SwigType *ty, const_String_or_char_ptr name) {
Node *node = NewHash();
Setattr(node, "type", ty);
Setattr(node, "name", name);
Setfile(node, Getfile(n));
Setline(node, Getline(n));
const String *tm = Swig_typemap_lookup("ffitype", node, "", 0);
Delete(node);
if (tm) {
return NewString(tm);
} 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);
}
if (SwigType_ispointer(type_reduced) || SwigType_isarray(ty) || !strncmp(type_reduced, "p.f", 3)) {
return NewString(":pointer-void");
}
for (i = 0; i < defined_foreign_types.count; i++) {
if (!Strcmp(ty, defined_foreign_types.entries[i])) {
return NewStringf("#.(%s \"%s\" :type :type)", identifier_converter, ty);
}
}
if (!Strncmp(type_reduced, "enum ", 5)) {
return NewString(":int");
}
Printf(stderr, "Unsupported data type: %s (was: %s)\n", type_reduced, ty);
SWIG_exit(EXIT_FAILURE);
}
return 0;
}
static String *get_lisp_type(Node *n, SwigType *ty, const_String_or_char_ptr name) {
Node *node = NewHash();
Setattr(node, "type", ty);
Setattr(node, "name", name);
Setfile(node, Getfile(n));
Setline(node, Getline(n));
const String *tm = Swig_typemap_lookup("lisptype", node, "", 0);
Delete(node);
return tm ? NewString(tm) : NewString("");
}
void UFFI::main(int argc, char *argv[]) {
int i;
Preprocessor_define("SWIGUFFI 1", 0);
SWIG_library_directory("uffi");
SWIG_config_file("uffi.swg");
for (i = 1; i < argc; i++) {
if (!strcmp(argv[i], "-identifier-converter")) {
char *conv = argv[i + 1];
if (!conv)
Swig_arg_error();
Swig_mark_arg(i);
Swig_mark_arg(i + 1);
i++;
/* check for built-ins */
if (!strcmp(conv, "lispify")) {
Delete(identifier_converter);
identifier_converter = NewString("identifier-convert-lispify");
} else if (!strcmp(conv, "null")) {
Delete(identifier_converter);
identifier_converter = NewString("identifier-convert-null");
} else {
/* Must be user defined */
Delete(identifier_converter);
identifier_converter = NewString(conv);
}
}
if (!strcmp(argv[i], "-help")) {
Printf(stdout, "%s\n", usage);
}
}
}
int UFFI::top(Node *n) {
String *module = Getattr(n, "name");
String *output_filename = NewString("");
File *f_null = NewString("");
Printf(output_filename, "%s%s.cl", SWIG_output_directory(), module);
f_cl = NewFile(output_filename, "w", SWIG_output_files());
if (!f_cl) {
FileErrorDisplay(output_filename);
SWIG_exit(EXIT_FAILURE);
}
Swig_register_filebyname("header", f_null);
Swig_register_filebyname("begin", f_null);
Swig_register_filebyname("runtime", f_null);
Swig_register_filebyname("wrapper", f_cl);
Swig_banner_target_lang(f_cl, ";;");
Printf(f_cl, "\n"
";; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; package: %s -*-\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);
Delete(f_cl); // Delete the handle, not the file
Delete(f_null);
return SWIG_OK;
}
int UFFI::functionWrapper(Node *n) {
String *funcname = Getattr(n, "sym:name");
ParmList *pl = Getattr(n, "parms");
Parm *p;
int argnum = 0, first = 1;
// int 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;
} else {
for (p = pl; p; p = nextSibling(p), argnum++) {
String *argname = Getattr(p, "name");
SwigType *argtype = Getattr(p, "type");
String *ffitype = get_ffi_type(n, argtype, argname);
String *lisptype = get_lisp_type(n, argtype, argname);
int tempargname = 0;
if (!argname) {
argname = NewStringf("arg%d", argnum);
tempargname = 1;
}
if (!first) {
Printf(f_cl, "\n ");
}
Printf(f_cl, "(%s %s %s)", argname, ffitype, lisptype);
first = 0;
Delete(ffitype);
Delete(lisptype);
if (tempargname)
Delete(argname);
}
}
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(n, Getattr(n, "type"), Swig_cresult_name())
//,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");
#if 0
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);
Delete(converted_value);
return SWIG_OK;
}
// Includes structs
int UFFI::classHandler(Node *n) {
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, " (name: %s)\n", name);
SWIG_exit(EXIT_FAILURE);
}
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");
if (type) {
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"));
SWIG_exit(EXIT_FAILURE);
}
/* Printf(stdout, "Converting %s in %s\n", type, name); */
lisp_type = get_ffi_type(n, 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) {
Language::membervariableHandler(n);
return SWIG_OK;
}
extern "C" Language *swig_uffi(void) {
return new UFFI();
}

View file

@ -113,7 +113,7 @@ static int is_digits(const String *str) {
const char *s = Char(str);
int isdigits = (*s != 0);
while (*s) {
if (!isdigit(*s)) {
if (!isdigit((int)*s)) {
isdigits = 0;
break;
}
@ -1686,7 +1686,7 @@ String *Preprocessor_parse(String *s) {
Seek(value, 0, SEEK_SET);
Swig_warning(WARN_PP_EVALUATION, Getfile(value), Getline(value), "Could not evaluate expression '%s'\n", value);
if (msg)
Swig_warning(WARN_PP_EVALUATION, Getfile(value), Getline(value), "Error: '%s'\n", msg);
Swig_warning(WARN_PP_EVALUATION, Getfile(value), Getline(value), "%s\n", msg);
allow = 0;
} else {
if (val == 0)
@ -1720,7 +1720,7 @@ String *Preprocessor_parse(String *s) {
Seek(value, 0, SEEK_SET);
Swig_warning(WARN_PP_EVALUATION, Getfile(value), Getline(value), "Could not evaluate expression '%s'\n", value);
if (msg)
Swig_warning(WARN_PP_EVALUATION, Getfile(value), Getline(value), "Error: '%s'\n", msg);
Swig_warning(WARN_PP_EVALUATION, Getfile(value), Getline(value), "%s\n", msg);
allow = 0;
} else {
if (val)

View file

@ -18,8 +18,19 @@
static Scanner *scan = 0;
typedef struct {
/* One of the EXPR_xxx values defined below. */
int op;
/* op == EXPR_OP: value is the token specifying which operator.
*
* op == EXPR_VALUE && svalue == NULL: Numeric expression value.
*
* Otherwise unused.
*/
long value;
/* op == EXPR_VALUE: If non-NULL, string expression value; if NULL see value.
*
* Otherwise unused.
*/
String *svalue;
} exprval;
@ -27,7 +38,12 @@ typedef struct {
#define EXPR_VALUE 2
#define EXPR_OP 3
#define EXPR_GROUP 4
#define EXPR_UMINUS 100
/* Special token values used here to distinguish from SWIG_TOKEN_MINUS
* and SWIG_TOKEN_PLUS (which we use here for a two argument versions).
*/
#define OP_UMINUS 100
#define OP_UPLUS 101
static exprval stack[256]; /* Parsing stack */
static int sp = 0; /* Stack pointer */
@ -38,7 +54,8 @@ static const char *errmsg = 0; /* Parsing error */
/* Initialize the precedence table for various operators. Low values have higher precedence */
static void init_precedence() {
prec[SWIG_TOKEN_NOT] = 10;
prec[EXPR_UMINUS] = 10;
prec[OP_UMINUS] = 10;
prec[OP_UPLUS] = 10;
prec[SWIG_TOKEN_STAR] = 20;
prec[SWIG_TOKEN_SLASH] = 20;
prec[SWIG_TOKEN_PERCENT] = 20;
@ -63,7 +80,8 @@ static void init_precedence() {
#define UNARY_OP(token) (((token) == SWIG_TOKEN_NOT) || \
((token) == SWIG_TOKEN_LNOT) || \
((token) == EXPR_UMINUS))
((token) == OP_UMINUS) || \
((token) == OP_UPLUS))
/* Reduce a single operator on the stack */
/* return 0 on failure, 1 on success */
@ -183,10 +201,14 @@ static int reduce_op() {
stack[sp - 1].value = !stack[sp].value;
sp--;
break;
case EXPR_UMINUS:
case OP_UMINUS:
stack[sp - 1].value = -stack[sp].value;
sp--;
break;
case OP_UPLUS:
stack[sp - 1].value = stack[sp].value;
sp--;
break;
case SWIG_TOKEN_SLASH:
if (stack[sp].value != 0) {
stack[sp - 2].value = stack[sp - 2].value / stack[sp].value;
@ -278,13 +300,15 @@ int Preprocessor_expr(DOH *s, int *error) {
/* Put initial state onto the stack */
stack[sp].op = EXPR_TOP;
stack[sp].value = 0;
while (1) {
/* Look at the top of the stack */
switch (stack[sp].op) {
case EXPR_TOP:
/* An expression. Can be a number or another expression enclosed in parens */
/* EXPR_TOP is a place-holder which can only appear on the top of the
* stack. We can reduce it to any expression - a number, a string, an
* unary operator, or another expression enclosed in parentheses.
*/
token = expr_token(scan);
if (!token) {
errmsg = "Expected an expression";
@ -296,26 +320,28 @@ int Preprocessor_expr(DOH *s, int *error) {
char *c = Char(Scanner_text(scan));
stack[sp].value = (long) strtol(c, 0, 0);
stack[sp].svalue = 0;
/* stack[sp].value = (long) atol(Char(Scanner_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)) {
} else if ((token == SWIG_TOKEN_MINUS) || (token == SWIG_TOKEN_PLUS) || (token == SWIG_TOKEN_LNOT) || (token == SWIG_TOKEN_NOT)) {
if (token == SWIG_TOKEN_MINUS)
token = EXPR_UMINUS;
token = OP_UMINUS;
else if (token == SWIG_TOKEN_PLUS)
token = OP_UPLUS;
stack[sp].value = token;
stack[sp++].op = EXPR_OP;
stack[sp].op = EXPR_OP;
sp++;
stack[sp].op = EXPR_TOP;
stack[sp].svalue = 0;
} else if (token == SWIG_TOKEN_LPAREN) {
stack[sp++].op = EXPR_GROUP;
stack[sp].op = EXPR_GROUP;
sp++;
stack[sp].op = EXPR_TOP;
stack[sp].value = 0;
stack[sp].svalue = 0;
} else if (token == SWIG_TOKEN_ENDLINE) {
} else if (token == SWIG_TOKEN_STRING) {
stack[sp].svalue = NewString(Scanner_text(scan));
stack[sp].op = EXPR_VALUE;
} else if (token == SWIG_TOKEN_ID) {
/* Defined macros have been expanded already so this is an unknown
* macro, which gets treated as zero.
*/
stack[sp].value = 0;
stack[sp].svalue = 0;
stack[sp].op = EXPR_VALUE;
@ -327,7 +353,9 @@ int Preprocessor_expr(DOH *s, int *error) {
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 */
/* A value is on top of the stack. We may reduce or evaluate depending
* on what the next token is.
*/
token = expr_token(scan);
if (!token) {
/* End of input. Might have to reduce if an operator is on stack */
@ -371,7 +399,6 @@ int Preprocessor_expr(DOH *s, int *error) {
stack[sp].value = token;
sp++;
stack[sp].op = EXPR_TOP;
stack[sp].value = 0;
} else {
if (stack[sp - 1].op != EXPR_OP)
goto syntax_error_expected_operator;
@ -390,7 +417,6 @@ int Preprocessor_expr(DOH *s, int *error) {
stack[sp].value = token;
sp++;
stack[sp].op = EXPR_TOP;
stack[sp].value = 0;
}
break;
case SWIG_TOKEN_RPAREN:
@ -406,6 +432,7 @@ int Preprocessor_expr(DOH *s, int *error) {
goto extra_rparen;
stack[sp - 1].op = EXPR_VALUE;
stack[sp - 1].value = stack[sp].value;
stack[sp - 1].svalue = stack[sp].svalue;
sp--;
break;
default:

View file

@ -13,13 +13,3 @@ SWIG Source directory
Source/Modules - Language modules.
Source/Include - Include files.
Historic directories which may be in CVS, but have been removed:
Source/Modules1.1 - Old SWIG-1.1 modules. Empty.
Source/LParse - Experimental parser. Officially dead
as CParse is more capable.
Source/SWIG1.1 - Old SWIG1.1 core. Completely empty now.

View file

@ -632,7 +632,7 @@ String *Swig_cppconstructor_director_call(const_String_or_char_ptr name, ParmLis
* If you define SWIG_FAST_REC_SEARCH, the method will set the found
* 'attr' in the target class 'n'. If not, the method will set the
* 'noattr' one. This prevents of having to navigate the entire
* hierarchy tree everytime, so, it is an O(1) method... or something
* hierarchy tree every time, so, it is an O(1) method... or something
* like that. However, it populates all the parsed classes with the
* 'attr' and/or 'noattr' attributes.
*
@ -1076,9 +1076,18 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas
/* 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, "sym:overloaded") && code) {
Append(mangled, Getattr(defaultargs ? defaultargs : n, "sym:overname"));
in C.
But when not using the suffix used for overloaded functions, we still need to ensure that the
wrapper name doesn't conflict with any wrapper functions, so make it sufficiently unique by
appending a suffix similar to the one used for overloaded functions to it.
*/
if (code) {
if (Getattr(n, "sym:overloaded")) {
Append(mangled, Getattr(defaultargs ? defaultargs : n, "sym:overname"));
} else {
Append(mangled, "__SWIG");
}
}
/* See if there is any code that we need to emit */

View file

@ -29,7 +29,7 @@ static int debug = 0;
* Swig_fragment_register()
*
* Add a fragment. Use the original Node*, so, if something needs to be
* changed, lang.cxx doesn't nedd to be touched again.
* changed, lang.cxx doesn't need to be touched again.
* ----------------------------------------------------------------------------- */
void Swig_fragment_register(Node *fragment) {

View file

@ -1157,47 +1157,15 @@ int Swig_scopename_check(const String *s) {
/* -----------------------------------------------------------------------------
* Swig_string_command()
*
* Executes a external command via popen with the string as a command
* line parameter. For example:
*
* Printf(stderr,"%(command:sed 's/[a-z]/\U\\1/' <<<)s","hello") -> Hello
* Feature removed in SWIG 4.1.0.
* ----------------------------------------------------------------------------- */
#if defined(_MSC_VER)
# define popen _popen
# define pclose _pclose
# if !defined(HAVE_POPEN)
# define HAVE_POPEN 1
# endif
#else
# if !defined(_WIN32)
/* These Posix functions are not ISO C and so are not always defined in stdio.h */
extern FILE *popen(const char *command, const char *type);
extern int pclose(FILE *stream);
# endif
#endif
String *Swig_string_command(String *s) {
String *res = NewStringEmpty();
#if defined(HAVE_POPEN)
if (Len(s)) {
char *command = Char(s);
FILE *fp = popen(command, "r");
if (fp) {
char buffer[1025];
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_exit(EXIT_FAILURE);
}
}
#endif
return res;
Swig_error("SWIG", Getline(s), "Command encoder no longer supported - use regex encoder instead.\n");
SWIG_exit(EXIT_FAILURE);
return 0;
}
/* -----------------------------------------------------------------------------
* Swig_string_strip()
*
@ -1312,7 +1280,8 @@ void Swig_offset_string(String *s, int number) {
#ifdef HAVE_PCRE
#include <pcre.h>
#define PCRE2_CODE_UNIT_WIDTH 8
#include <pcre2.h>
static int split_regex_pattern_subst(String *s, String **pattern, String **subst, const char **input)
{
@ -1375,7 +1344,7 @@ static void copy_with_maybe_case_conversion(String *dst, const char *src, int le
}
}
String *replace_captures(int num_captures, const char *input, String *subst, int captures[], String *pattern, String *s)
String *replace_captures(int num_captures, const char *input, String *subst, size_t captures[], String *pattern, String *s)
{
int convertCase = 0, convertNextOnly = 0;
String *result = NewStringEmpty();
@ -1397,7 +1366,7 @@ String *replace_captures(int num_captures, const char *input, String *subst, int
} else if (isdigit((unsigned char)*p)) {
int group = *p++ - '0';
if (group < num_captures) {
int l = captures[group*2], r = captures[group*2 + 1];
int l = (int)captures[group*2], r = (int)captures[group*2 + 1];
if (l != -1) {
copy_with_maybe_case_conversion(result, input + l, r - l, &convertCase, convertNextOnly);
}
@ -1449,26 +1418,31 @@ String *Swig_string_regex(String *s) {
const int pcre_options = 0;
String *res = 0;
pcre *compiled_pat = 0;
const char *pcre_error, *input;
int pcre_errorpos;
pcre2_code *compiled_pat = 0;
const char *input;
PCRE2_UCHAR pcre_error[256];
int pcre_errornum;
size_t pcre_errorpos;
String *pattern = 0, *subst = 0;
int captures[30];
size_t *captures = 0;
pcre2_match_data *match_data = 0;
if (split_regex_pattern_subst(s, &pattern, &subst, &input)) {
int rc;
compiled_pat = pcre_compile(
Char(pattern), pcre_options, &pcre_error, &pcre_errorpos, NULL);
compiled_pat = pcre2_compile(
(PCRE2_SPTR8)Char(pattern), PCRE2_ZERO_TERMINATED, pcre_options, &pcre_errornum, &pcre_errorpos, NULL);
if (!compiled_pat) {
pcre2_get_error_message (pcre_errornum, pcre_error, sizeof pcre_error);
Swig_error("SWIG", Getline(s), "PCRE compilation failed: '%s' in '%s':%i.\n",
pcre_error, Char(pattern), pcre_errorpos);
SWIG_exit(EXIT_FAILURE);
}
rc = pcre_exec(compiled_pat, NULL, input, (int)strlen(input), 0, 0, captures, 30);
match_data = pcre2_match_data_create_from_pattern (compiled_pat, NULL);
rc = pcre2_match(compiled_pat, (PCRE2_SPTR8)input, PCRE2_ZERO_TERMINATED, 0, 0, match_data, NULL);
captures = pcre2_get_ovector_pointer (match_data);
if (rc >= 0) {
res = replace_captures(rc, input, subst, captures, pattern, s);
} else if (rc != PCRE_ERROR_NOMATCH) {
} else if (rc != PCRE2_ERROR_NOMATCH) {
Swig_error("SWIG", Getline(s), "PCRE execution failed: error %d while matching \"%s\" using \"%s\".\n",
rc, Char(pattern), input);
SWIG_exit(EXIT_FAILURE);
@ -1477,12 +1451,19 @@ String *Swig_string_regex(String *s) {
DohDelete(pattern);
DohDelete(subst);
pcre_free(compiled_pat);
pcre2_code_free(compiled_pat);
pcre2_match_data_free(match_data);
return res ? res : NewStringEmpty();
}
String *Swig_pcre_version(void) {
return NewStringf("PCRE Version: %s", pcre_version());
int len = pcre2_config(PCRE2_CONFIG_VERSION, NULL);
char *buf = malloc(len);
String *result;
pcre2_config(PCRE2_CONFIG_VERSION, buf);
result = NewStringf("PCRE2 Version: %s", buf);
free(buf);
return result;
}
#else

View file

@ -1092,26 +1092,32 @@ static DOH *get_lattr(Node *n, List *lattr) {
}
#ifdef HAVE_PCRE
#include <pcre.h>
#define PCRE2_CODE_UNIT_WIDTH 8
#include <pcre2.h>
static int name_regexmatch_value(Node *n, String *pattern, String *s) {
pcre *compiled_pat;
const char *err;
int errpos;
pcre2_code *compiled_pat;
PCRE2_UCHAR err[256];
int errornum;
size_t errpos;
int rc;
compiled_pat = pcre_compile(Char(pattern), 0, &err, &errpos, NULL);
compiled_pat = pcre2_compile((PCRE2_SPTR8)Char(pattern), PCRE2_ZERO_TERMINATED, 0, &errornum, &errpos, NULL);
if (!compiled_pat) {
pcre2_get_error_message (errornum, err, sizeof err);
Swig_error("SWIG", Getline(n),
"Invalid regex \"%s\": compilation failed at %d: %s\n",
Char(pattern), errpos, err);
SWIG_exit(EXIT_FAILURE);
}
rc = pcre_exec(compiled_pat, NULL, Char(s), Len(s), 0, 0, NULL, 0);
pcre_free(compiled_pat);
pcre2_match_data *match_data = 0;
match_data = pcre2_match_data_create_from_pattern (compiled_pat, NULL);
rc = pcre2_match(compiled_pat, (PCRE2_SPTR8)Char(s), PCRE2_ZERO_TERMINATED, 0, 0, match_data, 0);
pcre2_code_free(compiled_pat);
pcre2_match_data_free(match_data);
if (rc == PCRE_ERROR_NOMATCH)
if (rc == PCRE2_ERROR_NOMATCH)
return 0;
if (rc < 0 ) {
@ -1132,6 +1138,7 @@ static int name_regexmatch_value(Node *n, String *pattern, String *s) {
Swig_error("SWIG", Getline(n),
"PCRE regex matching is not available in this SWIG build.\n");
SWIG_exit(EXIT_FAILURE);
return 0;
}
#endif /* HAVE_PCRE/!HAVE_PCRE */
@ -1510,20 +1517,30 @@ String *Swig_name_make(Node *n, String *prefix, const_String_or_char_ptr cname,
result = apply_rename(n, rename, fullname, prefix, name);
if ((msg) && (Len(msg))) {
if (!Getmeta(nname, "already_warned")) {
String* suffix = 0;
if (Strcmp(result, "$ignore") == 0) {
suffix = NewStringf(": ignoring '%s'\n", name);
} else if (Strcmp(result, name) != 0) {
suffix = NewStringf(", renaming to '%s'\n", result);
} else {
/* No rename was performed */
suffix = NewString("\n");
}
if (n) {
/* Parameter renaming is not fully implemented. Mainly because there is no C/C++ syntax to
* for %rename to fully qualify a function's parameter name from outside the function. Hence it
* is not possible to implemented targetted warning suppression on one parameter in one function. */
* is not possible to implemented targeted warning suppression on one parameter in one function. */
int suppress_parameter_rename_warning = Equal(nodeType(n), "parm");
if (!suppress_parameter_rename_warning) {
SWIG_WARN_NODE_BEGIN(n);
Swig_warning(0, Getfile(n), Getline(n), "%s\n", msg);
Swig_warning(0, Getfile(n), Getline(n), "%s%s", msg, suffix);
SWIG_WARN_NODE_END(n);
}
} else {
Swig_warning(0, Getfile(name), Getline(name), "%s\n", msg);
Swig_warning(0, Getfile(name), Getline(name), "%s%s", msg, suffix);
}
Setmeta(nname, "already_warned", "1");
Delete(suffix);
}
}
}

View file

@ -636,7 +636,7 @@ static int look(Scanner *s) {
}
else if (c == '.')
state = 100; /* Maybe a number, maybe just a period */
state = 100; /* Maybe a number, maybe ellipsis, just a period */
else if (isdigit(c))
state = 8; /* A numerical value */
else
@ -1330,19 +1330,34 @@ static int look(Scanner *s) {
}
break;
/* A period or maybe a floating point number */
/* A period or an ellipsis or maybe a floating point number */
case 100:
if ((c = nextchar(s)) == 0)
return (0);
if (isdigit(c))
state = 81;
else if (c == '.')
state = 101;
else {
retract(s, 1);
return SWIG_TOKEN_PERIOD;
}
break;
/* An ellipsis */
case 101:
if ((c = nextchar(s)) == 0)
return (0);
if (c == '.') {
return SWIG_TOKEN_ELLIPSIS;
} else {
retract(s, 2);
return SWIG_TOKEN_PERIOD;
}
break;
case 200: /* PLUS, PLUSPLUS, PLUSEQUAL */
if ((c = nextchar(s)) == 0)
return SWIG_TOKEN_PLUS;

View file

@ -134,7 +134,7 @@ SwigType *NewSwigType(int t) {
return NewString("double");
break;
case T_COMPLEX:
return NewString("complex");
return NewString("_Complex");
break;
case T_CHAR:
return NewString("char");
@ -1291,11 +1291,29 @@ void SwigType_typename_replace(SwigType *t, String *pat, String *rep) {
Replace(e, pat, rep, DOH_REPLACE_ANY);
} else if (SwigType_istemplate(e)) {
/* Replaces a type of the form 'pat<args>' with 'rep' */
if (Equal(e, pat)) {
String *repbase = SwigType_templateprefix(rep);
Replace(e, pat, repbase, DOH_REPLACE_ID | DOH_REPLACE_FIRST);
Delete(repbase);
{
/* To match "e=TemplateTemplateT<(float)>"
* with "pat=TemplateTemplateT"
* we need to compare only the first part of the string e.
*/
int len = Len(pat);
/* Len(e) > len, not >= (because we expect at least a
* character '<' following the template typename)
*/
if (Len(e) > len) {
String *firstPartOfType = NewStringWithSize(e, len);
const char* e_as_char = Char(e);
if (Equal(firstPartOfType, pat) && e_as_char[len] == '<') {
String *repbase = SwigType_templateprefix(rep);
Replace(e, pat, repbase, DOH_REPLACE_ID | DOH_REPLACE_FIRST);
Delete(repbase);
}
Delete(firstPartOfType);
}
}
{
String *tsuffix;
List *tparms = SwigType_parmlist(e);

View file

@ -70,6 +70,7 @@ extern void Scanner_locator(Scanner *, String *loc);
#define SWIG_TOKEN_BOOL 32 /* true or false */
#define SWIG_TOKEN_WSTRING 33 /* L"str" */
#define SWIG_TOKEN_WCHAR 34 /* L'c' */
#define SWIG_TOKEN_ELLIPSIS 35 /* ... */
#define SWIG_TOKEN_ILLEGAL 99
#define SWIG_TOKEN_ERROR -1

View file

@ -12,7 +12,7 @@
* ----------------------------------------------------------------------------- */
#include "swig.h"
#include "swigwarn.h"
#include "cparse.h"
#include <ctype.h>
/* #define SWIG_DEBUG*/
@ -641,10 +641,11 @@ void Swig_symbol_cadd(const_String_or_char_ptr name, Node *n) {
{
Node *td = n;
while (td && Checkattr(td, "nodeType", "cdecl") && Checkattr(td, "storage", "typedef")) {
while (td && ((Equal(nodeType(td), "cdecl") && Checkattr(td, "storage", "typedef")) || (Equal(nodeType(td), "using") && !Getattr(n, "namespace")))) {
SwigType *type;
Node *td1;
type = Copy(Getattr(td, "type"));
int using_not_typedef = Equal(nodeType(td), "using");
type = Copy(Getattr(td, using_not_typedef ? "uname" : "type"));
SwigType_push(type, Getattr(td, "decl"));
td1 = Swig_symbol_clookup(type, 0);
@ -665,9 +666,13 @@ void Swig_symbol_cadd(const_String_or_char_ptr name, Node *n) {
ie, when Foo -> FooBar -> Foo, jump one scope up when possible.
*/
if (td1 && Checkattr(td1, "storage", "typedef")) {
String *st = Getattr(td1, "type");
if (td1) {
String *st = 0;
String *sn = Getattr(td, "name");
if (Equal(nodeType(td1), "cdecl") && Checkattr(td1, "storage", "typedef"))
st = Getattr(td1, "type");
else if (Equal(nodeType(td1), "using") && !Getattr(td1, "namespace"))
st = Getattr(td1, "uname");
if (st && sn && Equal(st, sn)) {
Symtab *sc = Getattr(current_symtab, "parentNode");
if (sc)
@ -1177,7 +1182,9 @@ Node *Swig_symbol_clookup(const_String_or_char_ptr name, Symtab *n) {
Symtab *un = Getattr(s, "sym:symtab");
Node *ss = (!Equal(name, uname) || (un != n)) ? Swig_symbol_clookup(uname, un) : 0; /* avoid infinity loop */
if (!ss) {
SWIG_WARN_NODE_BEGIN(s);
Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", SwigType_namestr(Getattr(s, "uname")));
SWIG_WARN_NODE_END(s);
}
s = ss;
}
@ -1249,7 +1256,9 @@ Node *Swig_symbol_clookup_check(const_String_or_char_ptr name, Symtab *n, int (*
Node *ss;
ss = Swig_symbol_clookup(Getattr(s, "uname"), Getattr(s, "sym:symtab"));
if (!ss && !checkfunc) {
SWIG_WARN_NODE_BEGIN(s);
Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", SwigType_namestr(Getattr(s, "uname")));
SWIG_WARN_NODE_END(s);
}
s = ss;
}
@ -1300,7 +1309,9 @@ Node *Swig_symbol_clookup_local(const_String_or_char_ptr name, Symtab *n) {
while (s && Checkattr(s, "nodeType", "using")) {
Node *ss = Swig_symbol_clookup_local(Getattr(s, "uname"), Getattr(s, "sym:symtab"));
if (!ss) {
SWIG_WARN_NODE_BEGIN(s);
Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", SwigType_namestr(Getattr(s, "uname")));
SWIG_WARN_NODE_END(s);
}
s = ss;
}
@ -1348,7 +1359,9 @@ Node *Swig_symbol_clookup_local_check(const_String_or_char_ptr name, Symtab *n,
while (s && Checkattr(s, "nodeType", "using")) {
Node *ss = Swig_symbol_clookup_local_check(Getattr(s, "uname"), Getattr(s, "sym:symtab"), checkfunc);
if (!ss && !checkfunc) {
SWIG_WARN_NODE_BEGIN(s);
Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", SwigType_namestr(Getattr(s, "uname")));
SWIG_WARN_NODE_END(s);
}
s = ss;
}

View file

@ -225,7 +225,7 @@ void removeNode(Node *n) {
/* Delete attributes */
Delattr(n,"parentNode");
Delattr(n,"nextSibling");
Delattr(n,"prevSibling");
Delattr(n,"previousSibling");
}
/* -----------------------------------------------------------------------------

View file

@ -1256,6 +1256,59 @@ static String *typemap_warn(const_String_or_char_ptr tmap_method, Parm *p) {
return w ? Copy(w) : 0;
}
/* -----------------------------------------------------------------------------
* typemap_merge_fragment_kwargs()
*
* If multiple 'fragment' attributes are provided to a typemap, combine them by
* concatenating with commas.
* ----------------------------------------------------------------------------- */
static void typemap_merge_fragment_kwargs(Parm *kw) {
Parm *reattach_kw = NULL;
Parm *prev_kw = NULL;
Parm *next_kw = NULL;
String *fragment = NULL;
while (kw) {
next_kw = nextSibling(kw);
if (Strcmp(Getattr(kw, "name"), "fragment") == 0) {
String *thisfragment = Getattr(kw, "value");
String *kwtype = Getattr(kw, "type");
if (!fragment) {
/* First fragment found; it should remain in the list */
fragment = thisfragment;
prev_kw = kw;
} else {
/* Concatenate to previously found fragment */
Printv(fragment, ",", thisfragment, NULL);
reattach_kw = prev_kw;
}
if (kwtype) {
String *mangle = Swig_string_mangle(kwtype);
Append(fragment, mangle);
Delete(mangle);
/* Remove 'type' from kwargs so it's not duplicated later */
Setattr(kw, "type", NULL);
}
} else {
/* Not a fragment */
if (reattach_kw) {
/* Update linked list to remove duplicate fragment */
DohIncref(kw);
set_nextSibling(reattach_kw, kw);
set_previousSibling(kw, reattach_kw);
Delete(reattach_kw);
reattach_kw = NULL;
}
prev_kw = kw;
}
kw = next_kw;
}
if (reattach_kw) {
/* Update linked list to remove duplicate fragment */
set_nextSibling(reattach_kw, kw);
}
}
/* -----------------------------------------------------------------------------
* Swig_typemap_lookup()
*
@ -1463,6 +1516,7 @@ static String *Swig_typemap_lookup_impl(const_String_or_char_ptr tmap_method, No
/* Attach kwargs - ie the typemap attributes */
kw = Getattr(tm, "kwargs");
typemap_merge_fragment_kwargs(kw);
while (kw) {
String *value = Copy(Getattr(kw, "value"));
String *kwtype = Getattr(kw, "type");
@ -1577,6 +1631,7 @@ String *Swig_typemap_lookup(const_String_or_char_ptr tmap_method, Node *node, co
static void typemap_attach_kwargs(Hash *tm, const_String_or_char_ptr tmap_method, Parm *firstp, int nmatch) {
String *temp = NewStringEmpty();
Parm *kw = Getattr(tm, "kwargs");
typemap_merge_fragment_kwargs(kw);
while (kw) {
String *value = Copy(Getattr(kw, "value"));
String *type = Getattr(kw, "type");

View file

@ -488,6 +488,7 @@ SwigType *SwigType_del_reference(SwigType *t) {
char *c = Char(t);
int check = strncmp(c, "r.", 2);
assert(check == 0);
(void)check;
Delslice(t, 0, 2);
return t;
}
@ -523,6 +524,7 @@ SwigType *SwigType_del_rvalue_reference(SwigType *t) {
char *c = Char(t);
int check = strncmp(c, "z.", 2);
assert(check == 0);
(void)check;
Delslice(t, 0, 2);
return t;
}
@ -613,6 +615,7 @@ SwigType *SwigType_del_qualifier(SwigType *t) {
char *c = Char(t);
int check = strncmp(c, "q(", 2);
assert(check == 0);
(void)check;
Delslice(t, 0, element_size(c));
return t;
}
@ -681,6 +684,7 @@ SwigType *SwigType_del_memberpointer(SwigType *t) {
char *c = Char(t);
int check = strncmp(c, "m(", 2);
assert(check == 0);
(void)check;
Delslice(t, 0, element_size(c));
return t;
}
@ -725,6 +729,7 @@ SwigType *SwigType_del_array(SwigType *t) {
char *c = Char(t);
int check = strncmp(c, "a(", 2);
assert(check == 0);
(void)check;
Delslice(t, 0, element_size(c));
return t;
}

View file

@ -1453,11 +1453,11 @@ int SwigType_type(const SwigType *t) {
return T_DOUBLE;
if (strcmp(c, "long double") == 0)
return T_LONGDOUBLE;
if (!cparse_cplusplus && (strcmp(c, "float complex") == 0))
if (!cparse_cplusplus && (strcmp(c, "float _Complex") == 0))
return T_FLTCPLX;
if (!cparse_cplusplus && (strcmp(c, "double complex") == 0))
if (!cparse_cplusplus && (strcmp(c, "double _Complex") == 0))
return T_DBLCPLX;
if (!cparse_cplusplus && (strcmp(c, "complex") == 0))
if (!cparse_cplusplus && (strcmp(c, "_Complex") == 0))
return T_COMPLEX;
if (strcmp(c, "void") == 0)
return T_VOID;