Message ID | CADzB+2=nUE9Ma58PpzfaC97+TxXd3bBJ3Er_ZeAQjXogfUsEcw@mail.gmail.com |
---|---|
State | New |
Headers | show |
On 05/18/2017 08:30 PM, Jason Merrill wrote: > I got tired of writing strcmp (IDENTIFIER_POINTER and decided to wrap > it in an inline function. I decided to use "id_strcmp" instead of > just overloading strcmp, but I don't feel strongly about that choice. > > The second patch changes all existing uses of that pattern to use the > new function. > > OK for trunk? Since all the uses are of the form !id_strcmp(), would taking a step further and introducing a bool id_equal() be going too far? Besides being (arguably) easier to read, it would get around the question of whether it should be !id_strcmp() or id_strcmp == 0, or perhaps even 0 == id_strcmp(). Martin
diff --git a/gcc/tree.h b/gcc/tree.h index c6e883c..0f01149 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -3618,6 +3618,20 @@ tree_operand_check_code (const_tree __t, enum tree_code __code, int __i, #endif +/* strcmp of an identifier and a C string. */ + +inline int +id_strcmp (const_tree id, const char *str) +{ + return strcmp (IDENTIFIER_POINTER (id), str); +} + +inline int +id_strcmp (const char *str, const_tree id) +{ + return strcmp (str, IDENTIFIER_POINTER (id)); +} + #define error_mark_node global_trees[TI_ERROR_MARK] #define intQI_type_node global_trees[TI_INTQI_TYPE]