#include "ctf-parser.h"
#include "ctf-ast.h"
-__attribute__((visibility("hidden")))
+BT_HIDDEN
int yydebug;
/* Join two lists, put "add" at the end of "head". */
}
}
-__attribute__((visibility("hidden")))
+BT_HIDDEN
int yyparse(struct ctf_scanner *scanner);
-__attribute__((visibility("hidden")))
+BT_HIDDEN
int yylex(union YYSTYPE *yyval, struct ctf_scanner *scanner);
-__attribute__((visibility("hidden")))
+BT_HIDDEN
int yylex_init_extra(struct ctf_scanner *scanner, yyscan_t * ptr_yy_globals);
-__attribute__((visibility("hidden")))
+BT_HIDDEN
int yylex_destroy(yyscan_t yyscanner);
-__attribute__((visibility("hidden")))
+BT_HIDDEN
void yyrestart(FILE * in_str, yyscan_t scanner);
+BT_HIDDEN
+int yyget_lineno(yyscan_t yyscanner);
+BT_HIDDEN
+char *yyget_text(yyscan_t yyscanner);
struct gc_string {
struct bt_list_head gc;
[ NODE_STRUCT ] = "NODE_STRUCT",
};
-__attribute__((visibility("hidden")))
+BT_HIDDEN
const char *node_type(struct ctf_node *node)
{
if (node->type < NR_NODE_TYPES)
* gsrc will be garbage collected immediately, and gstr might be.
* Should only be used to append characters to a string literal or constant.
*/
-__attribute__((visibility("hidden")))
+BT_HIDDEN
struct gc_string *gc_string_append(struct ctf_scanner *scanner,
struct gc_string *gstr,
struct gc_string *gsrc)
return ret;
}
-__attribute__((visibility("hidden")))
+BT_HIDDEN
int is_type(struct ctf_scanner *scanner, const char *id)
{
struct ctf_scanner_scope *it;
return NULL;
memset(node, 0, sizeof(*node));
node->type = type;
+ node->lineno = yyget_lineno(scanner->scanner);
BT_INIT_LIST_HEAD(&node->tmp_head);
bt_list_add(&node->gc, &ast->allocated_nodes);
bt_list_add(&node->siblings, &node->tmp_head);
switch (type) {
case NODE_ROOT:
- fprintf(stderr, "[error] %s: trying to create root node\n", __func__);
+ printfn_fatal(node, "trying to create root node");
break;
case NODE_EVENT:
case NODE_UNKNOWN:
default:
- fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
- (int) type);
+ printfn_fatal(node, "unknown node type '%d'", (int) type);
break;
}
case NODE_UNKNOWN:
default:
- fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
- (int) parent->type);
+ printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
return -EINVAL;
}
return 0;
case NODE_UNKNOWN:
default:
- fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
- (int) parent->type);
+ printfn_fatal(node, "unknown node type %d", parent->type);
return -EINVAL;
}
return 0;
case NODE_UNKNOWN:
default:
- fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
- (int) parent->type);
+ printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
return -EINVAL;
}
return 0;
case NODE_UNKNOWN:
default:
- fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
- (int) parent->type);
+ printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
return -EINVAL;
}
return 0;
case NODE_UNKNOWN:
default:
- fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
- (int) parent->type);
+ printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
return -EINVAL;
}
return 0;
case NODE_UNKNOWN:
default:
- fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
- (int) parent->type);
+ printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
return -EINVAL;
}
return 0;
switch (node->type) {
case NODE_ROOT:
- fprintf(stderr, "[error] %s: trying to reparent root node\n", __func__);
+ printfn_fatal(node, "trying to reparent root node");
return -EINVAL;
case NODE_EVENT:
case NODE_UNKNOWN:
default:
- fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
- (int) parent->type);
+ printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
return -EINVAL;
}
return 0;
}
-__attribute__((visibility("hidden")))
+BT_HIDDEN
void yyerror(struct ctf_scanner *scanner, const char *str)
{
- fprintf(stderr, "error %s\n", str);
+ printfl_error(yyget_lineno(scanner->scanner),
+ "token \"%s\": %s\n",
+ yyget_text(scanner->scanner), str);
}
-__attribute__((visibility("hidden")))
+BT_HIDDEN
int yywrap(void)
{
return 1;
#define reparent_error(scanner, str) \
do { \
- yyerror(scanner, YY_("reparent_error: " str "\n")); \
+ yyerror(scanner, YY_("reparent_error: " str)); \
YYERROR; \
} while (0)
ret = yylex_init_extra(scanner, &scanner->scanner);
if (ret) {
- fprintf(stderr, "yylex_init error\n");
+ printf_fatal("yylex_init error");
goto cleanup_scanner;
}
/* Start processing new stream */
cleanup_lexer:
ret = yylex_destroy(scanner->scanner);
if (!ret)
- fprintf(stderr, "yylex_destroy error\n");
+ printf_fatal("yylex_destroy error");
cleanup_scanner:
free(scanner);
return NULL;
ctf_ast_free(scanner->ast);
ret = yylex_destroy(scanner->scanner);
if (ret)
- fprintf(stderr, "yylex_destroy error\n");
+ printf_error("yylex_destroy error");
free(scanner);
}
%define api.pure
/* %locations */
+%error-verbose
%parse-param {struct ctf_scanner *scanner}
%lex-param {struct ctf_scanner *scanner}
/*
postfix_expression
{ $$ = $1; }
| PLUS postfix_expression
- { $$ = $2; }
- | MINUS postfix_expression
{
$$ = $2;
- if ($$->u.unary_expression.type != UNARY_SIGNED_CONSTANT
- && $$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT)
+ if ($$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT
+ && $$->u.unary_expression.type != UNARY_SIGNED_CONSTANT) {
reparent_error(scanner, "expecting numeric constant");
-
+ }
+ }
+ | MINUS postfix_expression
+ {
+ $$ = $2;
if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
$$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
$$->u.unary_expression.u.signed_constant =
-($$->u.unary_expression.u.unsigned_constant);
- } else {
+ } else if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
$$->u.unary_expression.u.signed_constant =
-($$->u.unary_expression.u.signed_constant);
+ } else {
+ reparent_error(scanner, "expecting numeric constant");
}
}
;