#define ALLOC(ptr, size) do { \
(ptr) = malloc(size); \
- if (!(ptr)) \
- FAIL("failed to allocate memory"); \
+ if (!(ptr)) { \
+ cdecl__err(CDECL_ENOMEM); \
+ YYERROR; \
+ } \
} while (0)
#define ALLOC_STRUCT(ptr, type, ...) do { \
%code provides {
void cdecl__free(struct cdecl *);
-void cdecl__yyerror(YYLTYPE *, void *, struct cdecl **, const char *);
int cdecl__yyparse(void *scanner, struct cdecl **out);
}
{
free_decl(decl);
}
+
+static void
+yyerror(YYLTYPE *loc, yyscan_t scanner, struct cdecl **out, const char *err)
+{
+ if (strstr(err, "T_LEX_ERROR"))
+ return;
+
+ cdecl__err(CDECL_ENOPARSE, "%s", err);
+}
%}
%destructor { free($$); } <strval>
array: T_LBRACKET T_UINT T_RBRACKET {
if ($2 == 0)
- FAIL("array length must be positive");
+ FAIL(_("array length must be positive"));
ALLOC_STRUCT($$, struct cdecl_declarator,
.type = CDECL_DECL_ARRAY,
.u.array.vla = $3);
} | T_ARRAY T_UINT T_OF {
if ($2 == 0)
- FAIL("array length must be positive");
+ FAIL(_("array length must be positive"));
ALLOC_STRUCT($$, struct cdecl_declarator,
.type = CDECL_DECL_ARRAY,
ALLOC($$, sizeof "");
strcpy($$, "");
}
-
-%%
-void
-yyerror(YYLTYPE *loc, yyscan_t scanner, struct cdecl **out, const char *err)
-{
- if (strstr(err, "T_LEX_ERROR"))
- return;
-
- cdecl__set_error(&(const struct cdecl_error){
- .code = CDECL_ENOPARSE,
- .str = err,
- });
-}