generic_symlist_item:
symbol { $$ = symbol_list_sym_new ($1, @1); }
| TAG { $$ = symbol_list_type_new ($1, @1); }
-| "<*>" { $$ = symbol_list_default_tagged_new (@1); }
-| "<>" { $$ = symbol_list_default_tagless_new (@1); }
+| "<*>" { $$ = symbol_list_type_new ("*", @1); }
+| "<>" { $$ = symbol_list_type_new ("", @1); }
;
/* One token definition. */
}
-/*----------------------------------------.
-| Create a list containing a <*> at LOC. |
-`----------------------------------------*/
-
-symbol_list *
-symbol_list_default_tagged_new (location loc)
-{
- symbol_list *res = xmalloc (sizeof *res);
-
- res->content_type = SYMLIST_DEFAULT_TAGGED;
- res->location = res->sym_loc = loc;
- res->named_ref = NULL;
- res->next = NULL;
-
- return res;
-}
-
-
-/*---------------------------------------.
-| Create a list containing a <> at LOC. |
-`---------------------------------------*/
-
-symbol_list *
-symbol_list_default_tagless_new (location loc)
-{
- symbol_list *res = xmalloc (sizeof *res);
-
- res->content_type = SYMLIST_DEFAULT_TAGLESS;
- res->location = res->sym_loc = loc;
- res->named_ref = NULL;
- res->next = NULL;
-
- return res;
-}
-
-
/*-----------------------------------------------------------------------.
| Print this list, for which every content_type must be SYMLIST_SYMBOL. |
`-----------------------------------------------------------------------*/
if (node->content.sem_type->status == undeclared)
node->content.sem_type->status = used;
break;
- case SYMLIST_DEFAULT_TAGGED:
- default_tagged_code_props_set (kind, &cprops);
- break;
- case SYMLIST_DEFAULT_TAGLESS:
- default_tagless_code_props_set (kind, &cprops);
- break;
}
}
* \c <>.
*/
enum {
- SYMLIST_SYMBOL, SYMLIST_TYPE,
- SYMLIST_DEFAULT_TAGGED, SYMLIST_DEFAULT_TAGLESS
+ SYMLIST_SYMBOL,
+ SYMLIST_TYPE
} content_type;
union {
/**
/** Create a list containing \c type_name at \c loc. */
symbol_list *symbol_list_type_new (uniqstr type_name, location loc);
-/** Create a list containing a \c <*> at \c loc. */
-symbol_list *symbol_list_default_tagged_new (location loc);
-/** Create a list containing a \c <> at \c loc. */
-symbol_list *symbol_list_default_tagless_new (location loc);
-
/** Print this list.
\pre For every node \c n in the list, <tt>n->content_type =
symbol *startsymbol = NULL;
location startsymbol_location;
-/*---------------------------------------.
-| Default %destructor's and %printer's. |
-`---------------------------------------*/
-
-static code_props default_tagged_code_props[CODE_PROPS_SIZE] =
- {
- CODE_PROPS_NONE_INIT,
- CODE_PROPS_NONE_INIT,
- };
-static code_props default_tagless_code_props[CODE_PROPS_SIZE] =
- {
- CODE_PROPS_NONE_INIT,
- CODE_PROPS_NONE_INIT,
- };
/*---------------------------------.
| Create a new symbol, named TAG. |
}
/* Apply default code props's only to user-defined symbols. */
- if (sym->tag[0] == '$' || sym == errtoken)
- return &code_props_none;
-
- if (sym->type_name)
- return &default_tagged_code_props[kind];
- return &default_tagless_code_props[kind];
+ if (sym->tag[0] != '$' && sym != errtoken)
+ {
+ code_props *code =
+ &semantic_type_get (sym->type_name ? "*" : "", NULL)->props[kind];
+ if (code->code)
+ return code;
+ }
+ return &code_props_none;
}
/*-----------------------------------------------------------------.
static inline bool
semantic_type_check_defined (semantic_type *sem_type)
{
- if (sem_type->status == declared)
+ // <*> and <> do not have to be "declared".
+ if (sem_type->status == declared
+ || !*sem_type->tag
+ || STREQ(sem_type->tag, "*"))
{
for (int i = 0; i < 2; ++i)
if (sem_type->props[i].kind != CODE_PROPS_NONE
_("the start symbol %s is a token"),
startsymbol->tag);
}
-
-
-/*--------------------------------------------------.
-| Set default tagged/tagless %destructor/%printer. |
-`--------------------------------------------------*/
-
-void
-default_tagged_code_props_set (code_props_type kind, code_props const *code)
-{
- if (default_tagged_code_props[kind].code)
- {
- complain_at (code->location, complaint,
- _("redeclaration for default tagged %s"),
- code_props_type_string (kind));
- complain_at (default_tagged_code_props[kind].location, complaint,
- _("previous declaration"));
- }
- default_tagged_code_props[kind] = *code;
-}
-
-void
-default_tagless_code_props_set (code_props_type kind, code_props const *code)
-{
- if (default_tagless_code_props[kind].code)
- {
- complain_at (code->location, complaint,
- _("redeclaration for default tagless %s"),
- code_props_type_string (kind));
- complain_at (default_tagless_code_props[kind].location, complaint,
- _("previous declaration"));
- }
- default_tagless_code_props[kind] = *code;
-}
#token_translations. */
void symbols_pack (void);
-
-/*---------------------------------------.
-| Default %destructor's and %printer's. |
-`---------------------------------------*/
-
-/** Set the default \c \%destructor or \c \%printer for tagged values. */
-void default_tagged_code_props_set (code_props_type kind,
- code_props const *code);
-/** Set the default \c \%destructor or \c \%printer for tagless values. */
-void default_tagless_code_props_set (code_props_type kind,
- code_props const *destructor);
-
#endif /* !SYMTAB_H_ */
-# Executing Actions. -*- Autotest -*-
+e# Executing Actions. -*- Autotest -*-
# Copyright (C) 2001-2012 Free Software Foundation, Inc.
}
]])
-AT_BISON_CHECK([-o input.c input.y])
+AT_BISON_CHECK([-o input.c input.y], [], [],
+[[input.y:27.3-5: warning: useless %destructor for type <*> [-Wother]
+input.y:27.3-5: warning: useless %printer for type <*> [-Wother]
+]])
AT_COMPILE([input])
AT_PARSER_CHECK([./input], 1,
[[<> destructor for 'd' @ 4.
}
]])
-AT_BISON_CHECK([-o input.c input.y])
+AT_BISON_CHECK([-o input.c input.y], [], [],
+[[input.y:22.3-4: warning: useless %destructor for type <> [-Wother]
+input.y:22.3-4: warning: useless %printer for type <> [-Wother]
+]])
AT_COMPILE([input])
AT_PARSER_CHECK([./input], 1,
[[<*>/<field2>/e destructor.
AT_SETUP([Default %printer and %destructor for user-defined end token])
-# _AT_CHECK_DEFAULT_PRINTER_AND_DESTRUCTOR_FOR_END_TOKEN(TYPED)
-# -------------------------------------------------------------
-m4_define([_AT_CHECK_DEFAULT_PRINTER_AND_DESTRUCTOR_FOR_END_TOKEN],
+# AT_TEST(TYPED)
+# --------------
+m4_pushdef([AT_TEST],
[m4_if($1, 0,
[m4_pushdef([kind], []) m4_pushdef([not_kind], [*])],
[m4_pushdef([kind], [*]) m4_pushdef([not_kind], [])])
]])
AT_BISON_OPTION_POPDEFS
-AT_BISON_CHECK([-o input$1.c input$1.y])
+AT_BISON_CHECK([-o input$1.c input$1.y], [], [],
+[m4_if([$1], [0],
+[[input0.y:27.3-5: warning: useless %destructor for type <*> [-Wother]
+input0.y:27.3-5: warning: useless %printer for type <*> [-Wother]
+]],
+[[input1.y:27.3-4: warning: useless %destructor for type <> [-Wother]
+input1.y:27.3-4: warning: useless %printer for type <> [-Wother]
+]])])
+
AT_COMPILE([input$1])
+
AT_PARSER_CHECK([./input$1], 0,
[[<]]kind[[> for 'E' @ 1.
<]]kind[[> for 'S' @ 1.
m4_popdef([not_kind])
])
-_AT_CHECK_DEFAULT_PRINTER_AND_DESTRUCTOR_FOR_END_TOKEN(0)
-_AT_CHECK_DEFAULT_PRINTER_AND_DESTRUCTOR_FOR_END_TOKEN(1)
+AT_TEST(0)
+AT_TEST(1)
+
+m4_popdef([AT_TEST])
AT_CLEANUP
]])
AT_BISON_OPTION_POPDEFS
-AT_BISON_CHECK([-o input.c input.y])
+AT_BISON_CHECK([-o input.c input.y], [], [],
+[[input.y:21.6-8: warning: useless %destructor for type <*> [-Wother]
+input.y:21.6-8: warning: useless %printer for type <*> [-Wother]
+]])
AT_COMPILE([input])
AT_PARSER_CHECK([./input], [1], [],
[[Starting parse
]])
AT_BISON_OPTION_POPDEFS
-AT_BISON_CHECK([-o input.c input.y])
+AT_BISON_CHECK([-o input.c input.y], [], [],
+[[input.y:22.3-4: warning: useless %destructor for type <> [-Wother]
+input.y:22.3-4: warning: useless %printer for type <> [-Wother]
+]])
AT_COMPILE([input])
AT_CLEANUP
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-o input.c input.y], 0,,
-[[input.y:33.3-23: warning: unset value: $$ [-Wother]
+[[input.y:24.70-72: warning: useless %destructor for type <*> [-Wother]
+input.y:24.70-72: warning: useless %printer for type <*> [-Wother]
+input.y:33.3-23: warning: unset value: $$ [-Wother]
input.y:30.3-35.37: warning: unused value: $3 [-Wother]
]])
]])
AT_BISON_CHECK([input.y], [1], [],
-[[input.y:1.13-29: redeclaration for default tagged %destructor
+[[input.y:1.13-29: %destructor redeclaration for <*>
input.y:1.13-29: previous declaration
-input.y:2.10-24: redeclaration for default tagged %printer
+input.y:2.10-24: %printer redeclaration for <*>
input.y:2.10-24: previous declaration
-input.y:4.13-29: redeclaration for default tagged %destructor
+input.y:4.13-29: %destructor redeclaration for <*>
input.y:1.13-29: previous declaration
-input.y:5.10-24: redeclaration for default tagged %printer
+input.y:5.10-24: %printer redeclaration for <*>
input.y:2.10-24: previous declaration
-input.y:7.13-29: redeclaration for default tagless %destructor
+input.y:7.13-29: %destructor redeclaration for <>
input.y:7.13-29: previous declaration
-input.y:8.10-24: redeclaration for default tagless %printer
+input.y:8.10-24: %printer redeclaration for <>
input.y:8.10-24: previous declaration
-input.y:10.13-29: redeclaration for default tagless %destructor
+input.y:10.13-29: %destructor redeclaration for <>
input.y:7.13-29: previous declaration
-input.y:11.10-24: redeclaration for default tagless %printer
+input.y:11.10-24: %printer redeclaration for <>
input.y:8.10-24: previous declaration
-input.y:17.13-29: redeclaration for default tagged %destructor
+input.y:17.13-29: %destructor redeclaration for <*>
input.y:4.13-29: previous declaration
-input.y:18.10-24: redeclaration for default tagged %printer
+input.y:18.10-24: %printer redeclaration for <*>
input.y:5.10-24: previous declaration
-input.y:20.13-29: redeclaration for default tagless %destructor
+input.y:20.13-29: %destructor redeclaration for <>
input.y:10.13-29: previous declaration
-input.y:21.10-24: redeclaration for default tagless %printer
+input.y:21.10-24: %printer redeclaration for <>
input.y:11.10-24: previous declaration
]])
AT_SETUP([Useless printers or destructors])
-AT_DATA([[input.y]],
-[[%token <type1> token1
+# AT_TEST([INPUT], [STDERR])
+# --------------------------
+m4_pushdef([AT_TEST],
+[AT_DATA([[input.y]],
+[$1
+])
+AT_BISON_CHECK([input.y], [0], [], [$2
+])])
+
+AT_TEST([[%token <type1> token1
%token <type2> token2
%token <type3> token3
%token <type4> token4
%destructor {} <type7>
%%
-exp: "a";
-]])
-
-AT_BISON_CHECK([input.y], [0], [],
+exp: "a";]],
[[input.y:16.13-19: warning: useless %printer for type <type1> [-Wother]
-input.y:17.16-22: warning: useless %destructor for type <type2> [-Wother]
-]])
+input.y:17.16-22: warning: useless %destructor for type <type2> [-Wother]]])
+
+# If everybody is typed, <> is useless.
+AT_TEST([[%type <type> exp
+%token <type> a
+%printer {} <> <*>
+%%
+exp: a;]],
+[[input.y:3.13-14: warning: useless %printer for type <> [-Wother]]])
+# If nobody is is typed, <*> is useless.
+AT_TEST([[%token a
+%printer {} <> <*>
+%%
+exp: a;]],
+[[input.y:2.16-18: warning: useless %printer for type <*> [-Wother]]])
+
+m4_popdef([AT_TEST])
AT_CLEANUP