Re-organise parser grammar for initializer rules

Simply split initializer into const_cpp and initializer
This commit is contained in:
William S Fulton 2017-08-26 23:23:54 +01:00
commit 8227c02267

View file

@ -3090,7 +3090,7 @@ c_declaration : c_decl {
A C global declaration of some kind (may be variable, function, typedef, etc.) A C global declaration of some kind (may be variable, function, typedef, etc.)
------------------------------------------------------------ */ ------------------------------------------------------------ */
c_decl : storage_class type declarator initializer c_decl_tail { c_decl : storage_class type declarator cpp_const initializer c_decl_tail {
String *decl = $3.type; String *decl = $3.type;
$$ = new_node("cdecl"); $$ = new_node("cdecl");
if ($4.qualifier) if ($4.qualifier)
@ -3101,26 +3101,26 @@ c_decl : storage_class type declarator initializer c_decl_tail {
Setattr($$,"name",$3.id); Setattr($$,"name",$3.id);
Setattr($$,"decl",decl); Setattr($$,"decl",decl);
Setattr($$,"parms",$3.parms); Setattr($$,"parms",$3.parms);
Setattr($$,"value",$4.val); Setattr($$,"value",$5.val);
Setattr($$,"throws",$4.throws); Setattr($$,"throws",$4.throws);
Setattr($$,"throw",$4.throwf); Setattr($$,"throw",$4.throwf);
Setattr($$,"noexcept",$4.nexcept); Setattr($$,"noexcept",$4.nexcept);
if ($4.val && $4.type) { if ($5.val && $5.type) {
/* store initializer type as it might be different to the declared type */ /* store initializer type as it might be different to the declared type */
SwigType *valuetype = NewSwigType($4.type); SwigType *valuetype = NewSwigType($5.type);
if (Len(valuetype) > 0) if (Len(valuetype) > 0)
Setattr($$,"valuetype",valuetype); Setattr($$,"valuetype",valuetype);
else else
Delete(valuetype); Delete(valuetype);
} }
if (!$5) { if (!$6) {
if (Len(scanner_ccode)) { if (Len(scanner_ccode)) {
String *code = Copy(scanner_ccode); String *code = Copy(scanner_ccode);
Setattr($$,"code",code); Setattr($$,"code",code);
Delete(code); Delete(code);
} }
} else { } else {
Node *n = $5; Node *n = $6;
/* Inherit attributes */ /* Inherit attributes */
while (n) { while (n) {
String *type = Copy($2); String *type = Copy($2);
@ -3130,8 +3130,8 @@ c_decl : storage_class type declarator initializer c_decl_tail {
Delete(type); Delete(type);
} }
} }
if ($4.bitfield) { if ($5.bitfield) {
Setattr($$,"bitfield", $4.bitfield); Setattr($$,"bitfield", $5.bitfield);
} }
if ($3.id) { if ($3.id) {
@ -3146,18 +3146,18 @@ c_decl : storage_class type declarator initializer c_decl_tail {
String *lstr = Swig_scopename_last($3.id); String *lstr = Swig_scopename_last($3.id);
Setattr($$, "name", lstr); Setattr($$, "name", lstr);
Delete(lstr); Delete(lstr);
set_nextSibling($$, $5); set_nextSibling($$, $6);
} else { } else {
Delete($$); Delete($$);
$$ = $5; $$ = $6;
} }
Delete(p); Delete(p);
} else { } else {
Delete($$); Delete($$);
$$ = $5; $$ = $6;
} }
} else { } else {
set_nextSibling($$, $5); set_nextSibling($$, $6);
} }
} else { } else {
Swig_error(cparse_file, cparse_line, "Missing symbol name for global declaration\n"); Swig_error(cparse_file, cparse_line, "Missing symbol name for global declaration\n");
@ -3166,7 +3166,7 @@ c_decl : storage_class type declarator initializer c_decl_tail {
} }
/* Alternate function syntax introduced in C++11: /* Alternate function syntax introduced in C++11:
auto funcName(int x, int y) -> int; */ auto funcName(int x, int y) -> int; */
| storage_class AUTO declarator cpp_const ARROW cpp_alternate_rettype initializer c_decl_tail { | storage_class AUTO declarator cpp_const ARROW cpp_alternate_rettype cpp_const initializer c_decl_tail {
$$ = new_node("cdecl"); $$ = new_node("cdecl");
if ($4.qualifier) SwigType_push($3.type, $4.qualifier); if ($4.qualifier) SwigType_push($3.type, $4.qualifier);
Setattr($$,"refqualifier",$4.refqualifier); Setattr($$,"refqualifier",$4.refqualifier);
@ -3179,14 +3179,14 @@ c_decl : storage_class type declarator initializer c_decl_tail {
Setattr($$,"throws",$4.throws); Setattr($$,"throws",$4.throws);
Setattr($$,"throw",$4.throwf); Setattr($$,"throw",$4.throwf);
Setattr($$,"noexcept",$4.nexcept); Setattr($$,"noexcept",$4.nexcept);
if (!$8) { if (!$9) {
if (Len(scanner_ccode)) { if (Len(scanner_ccode)) {
String *code = Copy(scanner_ccode); String *code = Copy(scanner_ccode);
Setattr($$,"code",code); Setattr($$,"code",code);
Delete(code); Delete(code);
} }
} else { } else {
Node *n = $8; Node *n = $9;
while (n) { while (n) {
String *type = Copy($6); String *type = Copy($6);
Setattr(n,"type",type); Setattr(n,"type",type);
@ -3207,18 +3207,18 @@ c_decl : storage_class type declarator initializer c_decl_tail {
String *lstr = Swig_scopename_last($3.id); String *lstr = Swig_scopename_last($3.id);
Setattr($$,"name",lstr); Setattr($$,"name",lstr);
Delete(lstr); Delete(lstr);
set_nextSibling($$, $8); set_nextSibling($$, $9);
} else { } else {
Delete($$); Delete($$);
$$ = $8; $$ = $9;
} }
Delete(p); Delete(p);
} else { } else {
Delete($$); Delete($$);
$$ = $8; $$ = $9;
} }
} else { } else {
set_nextSibling($$, $8); set_nextSibling($$, $9);
} }
} }
; ;
@ -3229,28 +3229,28 @@ c_decl_tail : SEMI {
$$ = 0; $$ = 0;
Clear(scanner_ccode); Clear(scanner_ccode);
} }
| COMMA declarator initializer c_decl_tail { | COMMA declarator cpp_const initializer c_decl_tail {
$$ = new_node("cdecl"); $$ = new_node("cdecl");
if ($3.qualifier) SwigType_push($2.type,$3.qualifier); if ($3.qualifier) SwigType_push($2.type,$3.qualifier);
Setattr($$,"refqualifier",$3.refqualifier); Setattr($$,"refqualifier",$3.refqualifier);
Setattr($$,"name",$2.id); Setattr($$,"name",$2.id);
Setattr($$,"decl",$2.type); Setattr($$,"decl",$2.type);
Setattr($$,"parms",$2.parms); Setattr($$,"parms",$2.parms);
Setattr($$,"value",$3.val); Setattr($$,"value",$4.val);
Setattr($$,"throws",$3.throws); Setattr($$,"throws",$3.throws);
Setattr($$,"throw",$3.throwf); Setattr($$,"throw",$3.throwf);
Setattr($$,"noexcept",$3.nexcept); Setattr($$,"noexcept",$3.nexcept);
if ($3.bitfield) { if ($4.bitfield) {
Setattr($$,"bitfield", $3.bitfield); Setattr($$,"bitfield", $4.bitfield);
} }
if (!$4) { if (!$5) {
if (Len(scanner_ccode)) { if (Len(scanner_ccode)) {
String *code = Copy(scanner_ccode); String *code = Copy(scanner_ccode);
Setattr($$,"code",code); Setattr($$,"code",code);
Delete(code); Delete(code);
} }
} else { } else {
set_nextSibling($$,$4); set_nextSibling($$, $5);
} }
} }
| LBRACE { | LBRACE {
@ -3270,19 +3270,6 @@ c_decl_tail : SEMI {
initializer : def_args { initializer : def_args {
$$ = $1; $$ = $1;
$$.qualifier = 0;
$$.refqualifier = 0;
$$.throws = 0;
$$.throwf = 0;
$$.nexcept = 0;
}
| qualifiers_exception_specification def_args {
$$ = $2;
$$.qualifier = $1.qualifier;
$$.refqualifier = $1.refqualifier;
$$.throws = $1.throws;
$$.throwf = $1.throwf;
$$.nexcept = $1.nexcept;
} }
; ;
@ -3425,7 +3412,7 @@ c_enum_decl : storage_class c_enum_key ename c_enum_inherit LBRACE enumlist RBR
Namespaceprefix = Swig_symbol_qualifiedscopename(0); Namespaceprefix = Swig_symbol_qualifiedscopename(0);
} }
} }
| storage_class c_enum_key ename c_enum_inherit LBRACE enumlist RBRACE declarator initializer c_decl_tail { | storage_class c_enum_key ename c_enum_inherit LBRACE enumlist RBRACE declarator cpp_const initializer c_decl_tail {
Node *n; Node *n;
SwigType *ty = 0; SwigType *ty = 0;
String *unnamed = 0; String *unnamed = 0;
@ -3472,8 +3459,8 @@ c_enum_decl : storage_class c_enum_key ename c_enum_inherit LBRACE enumlist RBR
SetFlag(n,"unnamedinstance"); SetFlag(n,"unnamedinstance");
Delete(cty); Delete(cty);
} }
if ($10) { if ($11) {
Node *p = $10; Node *p = $11;
set_nextSibling(n,p); set_nextSibling(n,p);
while (p) { while (p) {
SwigType *cty = Copy(ty); SwigType *cty = Copy(ty);
@ -3981,12 +3968,12 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
; ;
cpp_opt_declarators : SEMI { $$ = 0; } cpp_opt_declarators : SEMI { $$ = 0; }
| declarator initializer c_decl_tail { | declarator cpp_const initializer c_decl_tail {
$$ = new_node("cdecl"); $$ = new_node("cdecl");
Setattr($$,"name",$1.id); Setattr($$,"name",$1.id);
Setattr($$,"decl",$1.type); Setattr($$,"decl",$1.type);
Setattr($$,"parms",$1.parms); Setattr($$,"parms",$1.parms);
set_nextSibling($$,$3); set_nextSibling($$, $4);
} }
; ;
/* ------------------------------------------------------------ /* ------------------------------------------------------------