diff options
Diffstat (limited to 'Source/CParse/parser.y')
-rw-r--r-- | Source/CParse/parser.y | 163 |
1 files changed, 140 insertions, 23 deletions
diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index ce0c91c43..caac88e4d 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -447,6 +447,14 @@ static void add_symbols(Node *n) { n = nextSibling(n); continue; } + if (cparse_cplusplus) { + String *value = Getattr(n, "value"); + if (value && Strcmp(value, "delete") == 0) { + /* C++11 deleted definition / deleted function */ + SetFlag(n,"deleted"); + SetFlag(n,"feature:ignore"); + } + } if (only_csymbol || GetFlag(n,"feature:ignore")) { /* Only add to C symbol table and continue */ Swig_symbol_add(0, n); @@ -1661,6 +1669,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { String *bitfield; Parm *throws; String *throwf; + String *nexcept; } dtype; struct { char *type; @@ -1675,6 +1684,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { short have_parms; ParmList *throws; String *throwf; + String *nexcept; } decl; Parm *tparms; struct { @@ -1708,14 +1718,14 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { %token ILLEGAL CONSTANT %token NAME RENAME NAMEWARN EXTEND PRAGMA FEATURE VARARGS %token ENUM -%token CLASS TYPENAME PRIVATE PUBLIC PROTECTED COLON STATIC VIRTUAL FRIEND THROW CATCH EXPLICIT AUTO +%token CLASS TYPENAME PRIVATE PUBLIC PROTECTED COLON STATIC VIRTUAL FRIEND THROW CATCH EXPLICIT AUTO NOEXCEPT %token STATIC_ASSERT CONSTEXPR THREAD_LOCAL DECLTYPE /* C++11 keywords */ %token USING %token <node> NAMESPACE %token NATIVE INLINE %token TYPEMAP EXCEPT ECHO APPLY CLEAR SWIGTEMPLATE FRAGMENT %token WARN -%token LESSTHAN GREATERTHAN DELETE_KW +%token LESSTHAN GREATERTHAN DELETE_KW DEFAULT %token LESSTHANOREQUALTO GREATERTHANOREQUALTO EQUALTO NOTEQUALTO %token ARROW %token QUESTIONMARK @@ -1763,7 +1773,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { %type <node> kwargs options; /* Misc */ -%type <dtype> initializer cpp_const ; +%type <dtype> initializer cpp_const exception_specification; %type <id> storage_class; %type <pl> parms ptail rawparms varargs_parms ; %type <pl> templateparameters templateparameterstail; @@ -1775,7 +1785,7 @@ static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) { %type <str> ellipsis variadic; %type <type> type rawtype type_right anon_bitfield_type decltype ; %type <bases> base_list inherit raw_inherit; -%type <dtype> definetype def_args etype; +%type <dtype> definetype def_args etype default_delete deleted_definition explicit_default; %type <dtype> expr exprnum exprcompound valexpr; %type <id> ename ; %type <id> template_decl; @@ -3226,6 +3236,7 @@ c_decl : storage_class type declarator initializer c_decl_tail { Setattr($$,"value",$4.val); Setattr($$,"throws",$4.throws); Setattr($$,"throw",$4.throwf); + Setattr($$,"noexcept",$4.nexcept); if (!$5) { if (Len(scanner_ccode)) { String *code = Copy(scanner_ccode); @@ -3285,6 +3296,7 @@ c_decl : storage_class type declarator initializer c_decl_tail { Setattr($$,"value",$6.val); Setattr($$,"throws",$6.throws); Setattr($$,"throw",$6.throwf); + Setattr($$,"noexcept",$6.nexcept); if (!$7) { if (Len(scanner_ccode)) { String *code = Copy(scanner_ccode); @@ -3344,6 +3356,7 @@ c_decl_tail : SEMI { Setattr($$,"value",$3.val); Setattr($$,"throws",$3.throws); Setattr($$,"throw",$3.throwf); + Setattr($$,"noexcept",$3.nexcept); if ($3.bitfield) { Setattr($$,"bitfield", $3.bitfield); } @@ -3368,24 +3381,28 @@ initializer : def_args { $$.qualifier = 0; $$.throws = 0; $$.throwf = 0; + $$.nexcept = 0; } | type_qualifier def_args { $$ = $2; $$.qualifier = $1; $$.throws = 0; $$.throwf = 0; + $$.nexcept = 0; } - | THROW LPAREN parms RPAREN def_args { - $$ = $5; + | exception_specification def_args { + $$ = $2; $$.qualifier = 0; - $$.throws = $3; - $$.throwf = NewString("1"); + $$.throws = $1.throws; + $$.throwf = $1.throwf; + $$.nexcept = $1.nexcept; } - | type_qualifier THROW LPAREN parms RPAREN def_args { - $$ = $6; + | type_qualifier exception_specification def_args { + $$ = $3; $$.qualifier = $1; - $$.throws = $4; - $$.throwf = NewString("1"); + $$.throws = $2.throws; + $$.throwf = $2.throwf; + $$.nexcept = $2.nexcept; } ; @@ -3661,6 +3678,7 @@ c_constructor_decl : storage_class type LPAREN parms RPAREN ctor_end { } Setattr($$,"throws",$6.throws); Setattr($$,"throw",$6.throwf); + Setattr($$,"noexcept",$6.nexcept); err = 0; } } @@ -4690,12 +4708,15 @@ cpp_constructor_decl : storage_class type LPAREN parms RPAREN ctor_end { Setattr($$,"decl",decl); Setattr($$,"throws",$6.throws); Setattr($$,"throw",$6.throwf); + Setattr($$,"noexcept",$6.nexcept); if (Len(scanner_ccode)) { String *code = Copy(scanner_ccode); Setattr($$,"code",code); Delete(code); } SetFlag($$,"feature:new"); + if ($6.defarg) + Setattr($$,"value",$6.defarg); } else { $$ = 0; } @@ -4723,6 +4744,9 @@ cpp_destructor_decl : NOT idtemplate LPAREN parms RPAREN cpp_end { } Setattr($$,"throws",$6.throws); Setattr($$,"throw",$6.throwf); + Setattr($$,"noexcept",$6.nexcept); + if ($6.val) + Setattr($$,"value",$6.val); add_symbols($$); } @@ -4738,9 +4762,9 @@ cpp_destructor_decl : NOT idtemplate LPAREN parms RPAREN cpp_end { Delete(name); Setattr($$,"throws",$7.throws); Setattr($$,"throw",$7.throwf); - if ($7.val) { - Setattr($$,"value","0"); - } + Setattr($$,"noexcept",$7.nexcept); + if ($7.val) + Setattr($$,"value",$7.val); if (Len(scanner_ccode)) { String *code = Copy(scanner_ccode); Setattr($$,"code",code); @@ -4982,13 +5006,24 @@ cpp_swig_directive: pragma_directive { $$ = $1; } cpp_end : cpp_const SEMI { Clear(scanner_ccode); + $$.val = 0; $$.throws = $1.throws; $$.throwf = $1.throwf; + $$.nexcept = $1.nexcept; + } + | cpp_const EQUAL default_delete SEMI { + Clear(scanner_ccode); + $$.val = $3.val; + $$.throws = $1.throws; + $$.throwf = $1.throwf; + $$.nexcept = $1.nexcept; } | cpp_const LBRACE { skip_balanced('{','}'); + $$.val = 0; $$.throws = $1.throws; $$.throwf = $1.throwf; + $$.nexcept = $1.nexcept; } ; @@ -4999,6 +5034,7 @@ cpp_vend : cpp_const SEMI { $$.bitfield = 0; $$.throws = $1.throws; $$.throwf = $1.throwf; + $$.nexcept = $1.nexcept; } | cpp_const EQUAL definetype SEMI { Clear(scanner_ccode); @@ -5007,6 +5043,7 @@ cpp_vend : cpp_const SEMI { $$.bitfield = 0; $$.throws = $1.throws; $$.throwf = $1.throwf; + $$.nexcept = $1.nexcept; } | cpp_const LBRACE { skip_balanced('{','}'); @@ -5015,6 +5052,7 @@ cpp_vend : cpp_const SEMI { $$.bitfield = 0; $$.throws = $1.throws; $$.throwf = $1.throwf; + $$.nexcept = $1.nexcept; } ; @@ -5066,6 +5104,7 @@ storage_class : EXTERN { $$ = "extern"; } | FRIEND { $$ = "friend"; } | EXPLICIT { $$ = "explicit"; } | CONSTEXPR { $$ = "constexpr"; } + | STATIC CONSTEXPR { $$ = "static constexpr"; } | THREAD_LOCAL { $$ = "thread_local"; } | THREAD_LOCAL STATIC { $$ = "static thread_local"; } | STATIC THREAD_LOCAL { $$ = "static thread_local"; } @@ -5203,6 +5242,7 @@ def_args : EQUAL definetype { $$.bitfield = 0; $$.throws = 0; $$.throwf = 0; + $$.nexcept = 0; } } | EQUAL definetype LBRACKET expr RBRACKET { @@ -5215,6 +5255,7 @@ def_args : EQUAL definetype { $$.bitfield = 0; $$.throws = 0; $$.throwf = 0; + $$.nexcept = 0; } else { $$.val = NewStringf("%s[%s]",$2.val,$4.val); } @@ -5227,6 +5268,7 @@ def_args : EQUAL definetype { $$.bitfield = 0; $$.throws = 0; $$.throwf = 0; + $$.nexcept = 0; } | COLON expr { $$.val = 0; @@ -5235,6 +5277,7 @@ def_args : EQUAL definetype { $$.bitfield = $2.val; $$.throws = 0; $$.throwf = 0; + $$.nexcept = 0; } | empty { $$.val = 0; @@ -5243,6 +5286,7 @@ def_args : EQUAL definetype { $$.bitfield = 0; $$.throws = 0; $$.throwf = 0; + $$.nexcept = 0; } ; @@ -6143,11 +6187,16 @@ definetype : { /* scanner_check_typedef(); */ } expr { } else if ($$.type != T_CHAR && $$.type != T_WSTRING && $$.type != T_WCHAR) { $$.rawval = 0; } + $$.qualifier = 0; $$.bitfield = 0; $$.throws = 0; $$.throwf = 0; + $$.nexcept = 0; scanner_ignore_typedef(); } + | default_delete { + $$ = $1; + } /* | string { $$.val = NewString($1); @@ -6156,10 +6205,45 @@ definetype : { /* scanner_check_typedef(); */ } expr { $$.bitfield = 0; $$.throws = 0; $$.throwf = 0; + $$.nexcept = 0; } */ ; +default_delete : deleted_definition { + $$ = $1; + } + | explicit_default { + $$ = $1; + } + ; + +/* For C++ deleted definition '= delete' */ +deleted_definition : DELETE_KW { + $$.val = NewString("delete"); + $$.rawval = 0; + $$.type = T_STRING; + $$.qualifier = 0; + $$.bitfield = 0; + $$.throws = 0; + $$.throwf = 0; + $$.nexcept = 0; + } + ; + +/* For C++ explicitly defaulted functions '= default' */ +explicit_default : DEFAULT { + $$.val = NewString("default"); + $$.rawval = 0; + $$.type = T_STRING; + $$.qualifier = 0; + $$.bitfield = 0; + $$.throws = 0; + $$.throwf = 0; + $$.nexcept = 0; + } + ; + /* Some stuff for handling enums */ ename : ID { $$ = $1; } @@ -6276,6 +6360,7 @@ valexpr : exprnum { $$ = $1; } $$.bitfield = 0; $$.throws = 0; $$.throwf = 0; + $$.nexcept = 0; } | WCHARCONST { $$.val = NewString($1); @@ -6288,6 +6373,7 @@ valexpr : exprnum { $$ = $1; } $$.bitfield = 0; $$.throws = 0; $$.throwf = 0; + $$.nexcept = 0; } /* grouping */ @@ -6613,25 +6699,43 @@ opt_virtual : VIRTUAL | empty ; +exception_specification : THROW LPAREN parms RPAREN { + $$.throws = $3; + $$.throwf = NewString("1"); + $$.nexcept = 0; + } + | NOEXCEPT { + $$.throws = 0; + $$.throwf = 0; + $$.nexcept = NewString("true"); + } + + | NOEXCEPT LPAREN expr RPAREN { + $$.throws = 0; + $$.throwf = 0; + $$.nexcept = $3.val; + } + ; + cpp_const : type_qualifier { - $$.qualifier = $1; $$.throws = 0; $$.throwf = 0; + $$.nexcept = 0; + $$.qualifier = $1; } - | THROW LPAREN parms RPAREN { + | exception_specification { + $$ = $1; $$.qualifier = 0; - $$.throws = $3; - $$.throwf = NewString("1"); } - | type_qualifier THROW LPAREN parms RPAREN { + | type_qualifier exception_specification { + $$ = $2; $$.qualifier = $1; - $$.throws = $4; - $$.throwf = NewString("1"); } | empty { - $$.qualifier = 0; $$.throws = 0; $$.throwf = 0; + $$.nexcept = 0; + $$.qualifier = 0; } ; @@ -6641,6 +6745,7 @@ ctor_end : cpp_const ctor_initializer SEMI { $$.defarg = 0; $$.throws = $1.throws; $$.throwf = $1.throwf; + $$.nexcept = $1.nexcept; } | cpp_const ctor_initializer LBRACE { skip_balanced('{','}'); @@ -6648,6 +6753,7 @@ ctor_end : cpp_const ctor_initializer SEMI { $$.defarg = 0; $$.throws = $1.throws; $$.throwf = $1.throwf; + $$.nexcept = $1.nexcept; } | LPAREN parms RPAREN SEMI { Clear(scanner_ccode); @@ -6656,6 +6762,7 @@ ctor_end : cpp_const ctor_initializer SEMI { $$.defarg = 0; $$.throws = 0; $$.throwf = 0; + $$.nexcept = 0; } | LPAREN parms RPAREN LBRACE { skip_balanced('{','}'); @@ -6664,12 +6771,21 @@ ctor_end : cpp_const ctor_initializer SEMI { $$.defarg = 0; $$.throws = 0; $$.throwf = 0; + $$.nexcept = 0; } | EQUAL definetype SEMI { $$.have_parms = 0; $$.defarg = $2.val; $$.throws = 0; $$.throwf = 0; + $$.nexcept = 0; + } + | exception_specification EQUAL default_delete SEMI { + $$.have_parms = 0; + $$.defarg = $3.val; + $$.throws = $1.throws; + $$.throwf = $1.throwf; + $$.nexcept = $1.nexcept; } ; @@ -6711,6 +6827,7 @@ template_decl : LESSTHAN valparms GREATERTHAN { ; idstring : ID { $$ = $1; } + | default_delete { $$ = $1.val; } | string { $$ = $1; } ; |