Merge branch 'master' into doxygen

The way Python docstrings are indented has changed on master, so use the
standard inspect module in Python autodoc unit test to ignore the differences
in their indentation level between -builtin and non-builtin cases to make the
test still pass with the branch version, which avoids the use of different
(but almost identical) values in the test itself.
This commit is contained in:
Vadim Zeitlin 2016-12-05 02:14:51 +01:00
commit e668c47b70
1094 changed files with 39390 additions and 11483 deletions

View file

@ -58,6 +58,7 @@ extern "C" {
/* util.c */
extern void Swig_cparse_replace_descriptor(String *s);
extern SwigType *Swig_cparse_smartptr(Node *n);
extern void cparse_normalize_void(Node *);
extern Parm *Swig_cparse_parm(String *s);
extern ParmList *Swig_cparse_parms(String *s, Node *file_line_node);
@ -77,4 +78,7 @@ extern "C" {
#define SWIG_WARN_NODE_END(Node) \
if (wrnfilter) Swig_warnfilter(wrnfilter,0); \
}
#define COMPOUND_EXPR_VAL(dtype) \
((dtype).type == T_CHAR || (dtype).type == T_WCHAR ? (dtype).rawval : (dtype).val)
#endif

View file

@ -13,11 +13,14 @@
* some point. Beware.
* ----------------------------------------------------------------------------- */
/*
Removed until we know more about the min versions of Bison and Yacc required for this
to work, see Byacc man page: http://invisible-island.net/byacc/manpage/yacc.html
/* There are 6 known shift-reduce conflicts in this file, fail compilation if any
more are introduced.
Please don't increase the number of the conflicts if at all possible. And if
you really have no choice but to do it, make sure you clearly document each
new conflict in this file.
*/
%expect 6
*/
%{
#define yylex yylex
@ -160,6 +163,11 @@ static Node *copy_node(Node *n) {
Setattr(nn, key, k.item);
continue;
}
/* defaultargs will be patched back in later in update_defaultargs() */
if (strcmp(ckey,"defaultargs") == 0) {
Setattr(nn, "needs_defaultargs", "1");
continue;
}
/* Looks okay. Just copy the data using Copy */
ci = Copy(k.item);
Setattr(nn, key, ci);
@ -511,18 +519,24 @@ static void add_symbols(Node *n) {
SetFlag(n,"feature:ignore");
}
}
if (only_csymbol || GetFlag(n,"feature:ignore")) {
if (only_csymbol || GetFlag(n,"feature:ignore") || strncmp(Char(symname),"$ignore",7) == 0) {
/* Only add to C symbol table and continue */
Swig_symbol_add(0, n);
} else if (strncmp(Char(symname),"$ignore",7) == 0) {
char *c = Char(symname)+7;
SetFlag(n,"feature:ignore");
if (strlen(c)) {
SWIG_WARN_NODE_BEGIN(n);
Swig_warning(0,Getfile(n), Getline(n), "%s\n",c+1);
SWIG_WARN_NODE_END(n);
if (!only_csymbol && !GetFlag(n, "feature:ignore")) {
/* Print the warning attached to $ignore name, if any */
char *c = Char(symname) + 7;
if (strlen(c)) {
SWIG_WARN_NODE_BEGIN(n);
Swig_warning(0,Getfile(n), Getline(n), "%s\n",c+1);
SWIG_WARN_NODE_END(n);
}
/* If the symbol was ignored via "rename" and is visible, set also feature:ignore*/
SetFlag(n, "feature:ignore");
}
if (!GetFlag(n, "feature:ignore") && Strcmp(symname,"$ignore") == 0) {
/* Add feature:ignore if the symbol was explicitely ignored, regardless of visibility */
SetFlag(n, "feature:ignore");
}
Swig_symbol_add(0, n);
} else {
Node *c;
if ((wrn) && (Len(wrn))) {
@ -694,6 +708,32 @@ static void add_symbols_copy(Node *n) {
}
}
/* Add in the "defaultargs" attribute for functions in instantiated templates.
* n should be any instantiated template (class or start of linked list of functions). */
static void update_defaultargs(Node *n) {
if (n) {
Node *firstdefaultargs = n;
update_defaultargs(firstChild(n));
n = nextSibling(n);
/* recursively loop through nodes of all types, but all we really need are the overloaded functions */
while (n) {
update_defaultargs(firstChild(n));
if (!Getattr(n, "defaultargs")) {
if (Getattr(n, "needs_defaultargs")) {
Setattr(n, "defaultargs", firstdefaultargs);
Delattr(n, "needs_defaultargs");
} else {
firstdefaultargs = n;
}
} else {
/* Functions added in with %extend (for specialized template classes) will already have default args patched up */
assert(Getattr(n, "defaultargs") == firstdefaultargs);
}
n = nextSibling(n);
}
}
}
/* Check a set of declarations to see if any are pure-abstract */
static List *pure_abstracts(Node *n) {
@ -2632,6 +2672,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va
{
Node *nn = n;
Node *linklistend = 0;
Node *linkliststart = 0;
while (nn) {
Node *templnode = 0;
if (Strcmp(nodeType(nn),"template") == 0) {
@ -2713,7 +2754,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va
}
templnode = copy_node(nn);
update_nested_classes(templnode); /* update classes nested withing template */
update_nested_classes(templnode); /* update classes nested within template */
/* We need to set the node name based on name used to instantiate */
Setattr(templnode,"name",tname);
Delete(tname);
@ -2787,7 +2828,11 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va
Swig_symbol_setscope(csyms);
}
/* Merge in %extend methods for this class */
/* Merge in %extend methods for this class.
This only merges methods within %extend for a template specialized class such as
template<typename T> class K {}; %extend K<int> { ... }
The copy_node() call above has already added in the generic %extend methods such as
template<typename T> class K {}; %extend K { ... } */
/* !!! This may be broken. We may have to add the
%extend methods at the beginning of the class */
@ -2830,6 +2875,8 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va
}
/* all the overloaded templated functions are added into a linked list */
if (!linkliststart)
linkliststart = templnode;
if (nscope_inner) {
/* non-global namespace */
if (templnode) {
@ -2850,6 +2897,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va
}
nn = Getattr(nn,"sym:nextSibling"); /* repeat for overloaded templated functions. If a templated class there will never be a sibling. */
}
update_defaultargs(linkliststart);
}
Swig_symbol_setscope(tscope);
Delete(Namespaceprefix);
@ -2916,28 +2964,26 @@ c_declaration : c_decl {
SWIG_WARN_NODE_END($$);
}
| USING idcolon EQUAL type plain_declarator SEMI {
$$ = new_node("using");
/* Convert using statement to a typedef statement */
$$ = new_node("cdecl");
Setattr($$,"type",$4);
Setattr($$,"storage","typedef");
Setattr($$,"name",$2);
SwigType_push($4,$5.type);
Setattr($$,"uname",$4);
Setattr($$,"decl",$5.type);
SetFlag($$,"typealias");
add_symbols($$);
SWIG_WARN_NODE_BEGIN($$);
Swig_warning(WARN_CPP11_ALIAS_DECLARATION, cparse_file, cparse_line, "The 'using' keyword in type aliasing is not fully supported yet.\n");
SWIG_WARN_NODE_END($$);
$$ = 0; /* TODO - ignored for now */
}
| TEMPLATE LESSTHAN template_parms GREATERTHAN USING idcolon EQUAL type plain_declarator SEMI {
$$ = new_node("using");
/* Convert alias template to a "template" typedef statement */
$$ = new_node("template");
Setattr($$,"type",$8);
Setattr($$,"storage","typedef");
Setattr($$,"name",$6);
SwigType_push($8,$9.type);
Setattr($$,"uname",$8);
Setattr($$,"decl",$9.type);
Setattr($$,"templateparms",$3);
Setattr($$,"templatetype","cdecl");
SetFlag($$,"aliastemplate");
add_symbols($$);
SWIG_WARN_NODE_BEGIN($$);
Swig_warning(WARN_CPP11_ALIAS_TEMPLATE, cparse_file, cparse_line, "The 'using' keyword in template aliasing is not fully supported yet.\n");
SWIG_WARN_NODE_END($$);
$$ = 0; /* TODO - ignored for now */
}
;
@ -2957,6 +3003,14 @@ c_decl : storage_class type declarator initializer c_decl_tail {
Setattr($$,"throws",$4.throws);
Setattr($$,"throw",$4.throwf);
Setattr($$,"noexcept",$4.nexcept);
if ($4.val && $4.type) {
/* store initializer type as it might be different to the declared type */
SwigType *valuetype = NewSwigType($4.type);
if (Len(valuetype) > 0)
Setattr($$,"valuetype",valuetype);
else
Delete(valuetype);
}
if (!$5) {
if (Len(scanner_ccode)) {
String *code = Copy(scanner_ccode);
@ -2984,8 +3038,8 @@ c_decl : storage_class type declarator initializer c_decl_tail {
matches that of the declaration, then we will allow it. Otherwise, delete. */
String *p = Swig_scopename_prefix($3.id);
if (p) {
if ((Namespaceprefix && Strcmp(p,Namespaceprefix) == 0) ||
(inclass && Strcmp(p,Classprefix) == 0)) {
if ((Namespaceprefix && Strcmp(p, Namespaceprefix) == 0) ||
(Classprefix && Strcmp(p, Classprefix) == 0)) {
String *lstr = Swig_scopename_last($3.id);
Setattr($$,"name",lstr);
Delete(lstr);
@ -3040,8 +3094,8 @@ c_decl : storage_class type declarator initializer c_decl_tail {
if (Strstr($3.id,"::")) {
String *p = Swig_scopename_prefix($3.id);
if (p) {
if ((Namespaceprefix && Strcmp(p,Namespaceprefix) == 0) ||
(inclass && Strcmp(p,Classprefix) == 0)) {
if ((Namespaceprefix && Strcmp(p, Namespaceprefix) == 0) ||
(Classprefix && Strcmp(p, Classprefix) == 0)) {
String *lstr = Swig_scopename_last($3.id);
Setattr($$,"name",lstr);
Delete(lstr);
@ -3677,6 +3731,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
Swig_symbol_setscope(cscope);
Delete(Namespaceprefix);
Namespaceprefix = Swig_symbol_qualifiedscopename(0);
Classprefix = currentOuterClass ? Getattr(currentOuterClass, "Classprefix") : 0;
}
/* An unnamed struct, possibly with a typedef */
@ -3713,7 +3768,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
cparse_start_line = cparse_line;
currentOuterClass = $<node>$;
inclass = 1;
Classprefix = NewStringEmpty();
Classprefix = 0;
Delete(Namespaceprefix);
Namespaceprefix = Swig_symbol_qualifiedscopename(0);
/* save the structure declaration to make a typedef for it later*/
@ -3726,6 +3781,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
String *name = 0;
Node *n;
Classprefix = 0;
(void)$<node>5;
$$ = currentOuterClass;
currentOuterClass = Getattr($$, "nested:outer");
if (!currentOuterClass)
@ -3823,6 +3879,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
Delete($$);
$$ = $6; /* pass member list to outer class/namespace (instead of self)*/
}
Classprefix = currentOuterClass ? Getattr(currentOuterClass, "Classprefix") : 0;
}
;
@ -5871,7 +5928,7 @@ definetype : { /* scanner_check_typedef(); */ } expr {
if ($$.type == T_STRING) {
$$.rawval = NewStringf("\"%(escape)s\"",$$.val);
} else if ($$.type != T_CHAR && $$.type != T_WSTRING && $$.type != T_WCHAR) {
$$.rawval = 0;
$$.rawval = NewStringf("%s", $$.val);
}
$$.qualifier = 0;
$$.bitfield = 0;
@ -6180,81 +6237,81 @@ exprnum : NUM_INT { $$ = $1; }
;
exprcompound : expr PLUS expr {
$$.val = NewStringf("%s+%s",$1.val,$3.val);
$$.val = NewStringf("%s+%s", COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3));
$$.type = promote($1.type,$3.type);
}
| expr MINUS expr {
$$.val = NewStringf("%s-%s",$1.val,$3.val);
$$.val = NewStringf("%s-%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3));
$$.type = promote($1.type,$3.type);
}
| expr STAR expr {
$$.val = NewStringf("%s*%s",$1.val,$3.val);
$$.val = NewStringf("%s*%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3));
$$.type = promote($1.type,$3.type);
}
| expr SLASH expr {
$$.val = NewStringf("%s/%s",$1.val,$3.val);
$$.val = NewStringf("%s/%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3));
$$.type = promote($1.type,$3.type);
}
| expr MODULO expr {
$$.val = NewStringf("%s%%%s",$1.val,$3.val);
$$.val = NewStringf("%s%%%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3));
$$.type = promote($1.type,$3.type);
}
| expr AND expr {
$$.val = NewStringf("%s&%s",$1.val,$3.val);
$$.val = NewStringf("%s&%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3));
$$.type = promote($1.type,$3.type);
}
| expr OR expr {
$$.val = NewStringf("%s|%s",$1.val,$3.val);
$$.val = NewStringf("%s|%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3));
$$.type = promote($1.type,$3.type);
}
| expr XOR expr {
$$.val = NewStringf("%s^%s",$1.val,$3.val);
$$.val = NewStringf("%s^%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3));
$$.type = promote($1.type,$3.type);
}
| expr LSHIFT expr {
$$.val = NewStringf("%s << %s",$1.val,$3.val);
$$.val = NewStringf("%s << %s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3));
$$.type = promote_type($1.type);
}
| expr RSHIFT expr {
$$.val = NewStringf("%s >> %s",$1.val,$3.val);
$$.val = NewStringf("%s >> %s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3));
$$.type = promote_type($1.type);
}
| expr LAND expr {
$$.val = NewStringf("%s&&%s",$1.val,$3.val);
$$.val = NewStringf("%s&&%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3));
$$.type = cparse_cplusplus ? T_BOOL : T_INT;
}
| expr LOR expr {
$$.val = NewStringf("%s||%s",$1.val,$3.val);
$$.val = NewStringf("%s||%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3));
$$.type = cparse_cplusplus ? T_BOOL : T_INT;
}
| expr EQUALTO expr {
$$.val = NewStringf("%s==%s",$1.val,$3.val);
$$.val = NewStringf("%s==%s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3));
$$.type = cparse_cplusplus ? T_BOOL : T_INT;
}
| expr NOTEQUALTO expr {
$$.val = NewStringf("%s!=%s",$1.val,$3.val);
$$.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", $1.val, $3.val);
$$.val = NewStringf("%s > %s", COMPOUND_EXPR_VAL($1), COMPOUND_EXPR_VAL($3));
$$.type = cparse_cplusplus ? T_BOOL : T_INT;
}
| expr LESSTHAN expr {
$$.val = NewStringf("%s > %s", $1.val, $3.val);
$$.val = NewStringf("%s < %s", COMPOUND_EXPR_VAL($1), COMPOUND_EXPR_VAL($3));
$$.type = cparse_cplusplus ? T_BOOL : T_INT;
}
*/
| expr GREATERTHANOREQUALTO expr {
$$.val = NewStringf("%s >= %s", $1.val, $3.val);
$$.val = NewStringf("%s >= %s", COMPOUND_EXPR_VAL($1), COMPOUND_EXPR_VAL($3));
$$.type = cparse_cplusplus ? T_BOOL : T_INT;
}
| expr LESSTHANOREQUALTO expr {
$$.val = NewStringf("%s <= %s", $1.val, $3.val);
$$.val = NewStringf("%s <= %s", COMPOUND_EXPR_VAL($1), COMPOUND_EXPR_VAL($3));
$$.type = cparse_cplusplus ? T_BOOL : T_INT;
}
| expr QUESTIONMARK expr COLON expr %prec QUESTIONMARK {
$$.val = NewStringf("%s?%s:%s", $1.val, $3.val, $5.val);
$$.val = NewStringf("%s?%s:%s", COMPOUND_EXPR_VAL($1), COMPOUND_EXPR_VAL($3), COMPOUND_EXPR_VAL($5));
/* This may not be exactly right, but is probably good enough
* for the purposes of parsing constant expressions. */
$$.type = promote($3.type, $5.type);
@ -6272,7 +6329,7 @@ exprcompound : expr PLUS expr {
$$.type = $2.type;
}
| LNOT expr {
$$.val = NewStringf("!%s",$2.val);
$$.val = NewStringf("!%s",COMPOUND_EXPR_VAL($2));
$$.type = T_INT;
}
| type LPAREN {

View file

@ -70,6 +70,28 @@ void Swig_cparse_replace_descriptor(String *s) {
}
}
/* -----------------------------------------------------------------------------
* Swig_cparse_smartptr()
*
* Parse the type in smartptr feature and convert into a SwigType.
* Error out if the parsing fails as this is like a parser syntax error.
* ----------------------------------------------------------------------------- */
SwigType *Swig_cparse_smartptr(Node *n) {
SwigType *smart = 0;
String *smartptr = Getattr(n, "feature:smartptr");
if (smartptr) {
SwigType *cpt = Swig_cparse_type(smartptr);
if (cpt) {
smart = SwigType_typedef_resolve_all(cpt);
Delete(cpt);
} else {
Swig_error(Getfile(n), Getline(n), "Invalid type (%s) in 'smartptr' feature for class %s.\n", smartptr, SwigType_namestr(Getattr(n, "name")));
}
}
return smart;
}
/* -----------------------------------------------------------------------------
* cparse_normalize_void()
*