tracing: Combine enum and arrays into single macro in filter code

Instead of having a separate enum that is the index into another array, like
a string array, make a single macro that combines them into a single list,
and then the two can not get out of sync. This makes it easier to add and
remove items.

The macro trick is:

 #define DOGS				\
  C( JACK,     "Jack Russell")		\
  C( ITALIAN,  "Italian Greyhound")	\
  C( GERMAN,   "German Shepherd")

 #undef C
 #define C(a, b) a

 enum { DOGS };

 #undef C
 #define C(a, b) b

 static char dogs[] = { DOGS };
Reviewed-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
parent 567f6989
...@@ -33,22 +33,26 @@ ...@@ -33,22 +33,26 @@
"# Only events with the given fields will be affected.\n" \ "# Only events with the given fields will be affected.\n" \
"# If no events are modified, an error message will be displayed here" "# If no events are modified, an error message will be displayed here"
enum filter_op_ids #define OPS \
{ C( OP_OR, "||", 1 ), \
OP_OR, C( OP_AND, "&&", 2 ), \
OP_AND, C( OP_GLOB, "~", 4 ), \
OP_GLOB, C( OP_NE, "!=", 4 ), \
OP_NE, C( OP_EQ, "==", 4 ), \
OP_EQ, C( OP_LT, "<", 5 ), \
OP_LT, C( OP_LE, "<=", 5 ), \
OP_LE, C( OP_GT, ">", 5 ), \
OP_GT, C( OP_GE, ">=", 5 ), \
OP_GE, C( OP_BAND, "&", 6 ), \
OP_BAND, C( OP_NOT, "!", 6 ), \
OP_NOT, C( OP_NONE, "OP_NONE", 0 ), \
OP_NONE, C( OP_OPEN_PAREN, "(", 0 ), \
OP_OPEN_PAREN, C( OP_MAX, NULL, 0 )
};
#undef C
#define C(a, b, c) a
enum filter_op_ids { OPS };
struct filter_op { struct filter_op {
int id; int id;
...@@ -56,56 +60,36 @@ struct filter_op { ...@@ -56,56 +60,36 @@ struct filter_op {
int precedence; int precedence;
}; };
/* Order must be the same as enum filter_op_ids above */ #undef C
static struct filter_op filter_ops[] = { #define C(a, b, c) { a, b, c }
{ OP_OR, "||", 1 },
{ OP_AND, "&&", 2 },
{ OP_GLOB, "~", 4 },
{ OP_NE, "!=", 4 },
{ OP_EQ, "==", 4 },
{ OP_LT, "<", 5 },
{ OP_LE, "<=", 5 },
{ OP_GT, ">", 5 },
{ OP_GE, ">=", 5 },
{ OP_BAND, "&", 6 },
{ OP_NOT, "!", 6 },
{ OP_NONE, "OP_NONE", 0 },
{ OP_OPEN_PAREN, "(", 0 },
};
enum { static struct filter_op filter_ops[] = { OPS };
FILT_ERR_NONE,
FILT_ERR_INVALID_OP,
FILT_ERR_UNBALANCED_PAREN,
FILT_ERR_TOO_MANY_OPERANDS,
FILT_ERR_OPERAND_TOO_LONG,
FILT_ERR_FIELD_NOT_FOUND,
FILT_ERR_ILLEGAL_FIELD_OP,
FILT_ERR_ILLEGAL_INTVAL,
FILT_ERR_BAD_SUBSYS_FILTER,
FILT_ERR_TOO_MANY_PREDS,
FILT_ERR_MISSING_FIELD,
FILT_ERR_INVALID_FILTER,
FILT_ERR_IP_FIELD_ONLY,
FILT_ERR_ILLEGAL_NOT_OP,
};
static char *err_text[] = { #define ERRORS \
"No error", C( NONE, "No error"), \
"Invalid operator", C( INVALID_OP, "Invalid operator"), \
"Unbalanced parens", C( UNBALANCED_PAREN, "Unbalanced parens"), \
"Too many operands", C( TOO_MANY_OPERANDS, "Too many operands"), \
"Operand too long", C( OPERAND_TOO_LONG, "Operand too long"), \
"Field not found", C( FIELD_NOT_FOUND, "Field not found"), \
"Illegal operation for field type", C( ILLEGAL_FIELD_OP, "Illegal operation for field type"), \
"Illegal integer value", C( ILLEGAL_INTVAL, "Illegal integer value"), \
"Couldn't find or set field in one of a subsystem's events", C( BAD_SUBSYS_FILTER, "Couldn't find or set field in one of a subsystem's events"), \
"Too many terms in predicate expression", C( TOO_MANY_PREDS, "Too many terms in predicate expression"), \
"Missing field name and/or value", C( MISSING_FIELD, "Missing field name and/or value"), \
"Meaningless filter expression", C( INVALID_FILTER, "Meaningless filter expression"), \
"Only 'ip' field is supported for function trace", C( IP_FIELD_ONLY, "Only 'ip' field is supported for function trace"), \
"Illegal use of '!'", C( ILLEGAL_NOT_OP, "Illegal use of '!'"),
};
#undef C
#define C(a, b) FILT_ERR_##a
enum { ERRORS };
#undef C
#define C(a, b) b
static char *err_text[] = { ERRORS };
struct opstack_op { struct opstack_op {
enum filter_op_ids op; enum filter_op_ids op;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment