Use streq() instead of strcmp() == 0.
authorChristoph Mallon <christoph.mallon@gmx.de>
Wed, 14 Sep 2011 09:10:48 +0000 (11:10 +0200)
committerChristoph Mallon <christoph.mallon@gmx.de>
Wed, 14 Sep 2011 09:10:48 +0000 (11:10 +0200)
adt/strset.c
ast2firm.c
builtins.c
driver/firm_opt.c
format_check.c
lexer.c
parser.c
symbol_table.c
warning.c
wrappergen/write_jna.c

index 08eccf7..17e24ee 100644 (file)
@@ -20,6 +20,7 @@
 #include <config.h>
 
 #include "strset.h"
+#include "strutil.h"
 #include "hash_string.h"
 
 #define HashSet                    strset_t
@@ -30,7 +31,7 @@
 #define NullValue                  NULL
 #define DeletedValue               ((void*)-1)
 #define Hash(this, value)          hash_string(value)
-#define KeysEqual(this,key1,key2)  (strcmp(key1, key2) == 0)
+#define KeysEqual(this,key1,key2)  (streq(key1, key2))
 #define SetRangeEmpty(ptr,size)    memset(ptr, 0, (size) * sizeof(strset_entry_t))
 #define SCALAR_RETURN
 
index c07ee64..cb9b23e 100644 (file)
@@ -32,6 +32,7 @@
 
 #include "adt/error.h"
 #include "adt/array.h"
+#include "adt/strutil.h"
 #include "adt/util.h"
 #include "symbol_t.h"
 #include "token_t.h"
@@ -5085,7 +5086,7 @@ static void asm_statement_to_firm(const asm_statement_t *statement)
                        continue;
                }
 
-               if (strcmp(clobber_str, "memory") == 0) {
+               if (streq(clobber_str, "memory")) {
                        needs_memory = true;
                        continue;
                }
index 8236a4e..c70936d 100644 (file)
@@ -246,22 +246,22 @@ void adapt_special_functions(function_t *function)
        }
 
        if (name[0] == 's') {
-               if ((name[1] == 'e' && (!strcmp(name, "setjmp")
-                                    || !strcmp(name, "setjmp_syscall")))
-                   || (name[1] == 'i' && !strcmp(name, "sigsetjmp"))
-                   || (name[1] == 'a' && !strcmp(name, "savectx"))) {
+               if ((name[1] == 'e' && (streq(name, "setjmp")
+                                    || streq(name, "setjmp_syscall")))
+                   || (name[1] == 'i' && streq(name, "sigsetjmp"))
+                   || (name[1] == 'a' && streq(name, "savectx"))) {
                        function->base.type
                                = add_type_modifier(function->base.type, DM_RETURNS_TWICE);
-               } else if (name[1] == 'i' && !strcmp(name, "siglongjmp")) {
+               } else if (name[1] == 'i' && streq(name, "siglongjmp")) {
                        function->base.type
                                = add_type_modifier(function->base.type, DM_NORETURN);
                }
-       } else if ((name[0] == 'q' && !strcmp(name, "qsetjmp"))
-                  || (name[0] == 'v' && !strcmp(name, "vfork"))
-                  || (name[0] == 'g' && !strcmp(name, "getcontext"))) {
+       } else if ((name[0] == 'q' && streq(name, "qsetjmp"))
+                  || (name[0] == 'v' && streq(name, "vfork"))
+                  || (name[0] == 'g' && streq(name, "getcontext"))) {
                function->base.type
                        = add_type_modifier(function->base.type, DM_RETURNS_TWICE);
-       } else if (name[0] == 'l' && !strcmp(name, "longjmp")) {
+       } else if (name[0] == 'l' && streq(name, "longjmp")) {
                function->base.type
                        = add_type_modifier(function->base.type, DM_NORETURN);
        }
index f1535ba..50beb48 100644 (file)
@@ -408,7 +408,7 @@ static opt_config_t opts[] = {
 static opt_config_t *get_opt(const char *name)
 {
        FOR_EACH_OPT(config) {
-               if (strcmp(config->name, name) == 0)
+               if (streq(config->name, name))
                        return config;
        }
 
index 6fec9b7..5580d91 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <ctype.h>
 
+#include "adt/strutil.h"
 #include "adt/util.h"
 #include "format_check.h"
 #include "symbol_t.h"
@@ -1003,7 +1004,7 @@ void check_format(const call_expression_t *const call)
         */
        const char *const name = entity->base.symbol->string;
        for (size_t i = 0; i < lengthof(builtin_table); ++i) {
-               if (strcmp(name, builtin_table[i].name) == 0) {
+               if (streq(name, builtin_table[i].name)) {
                        switch (builtin_table[i].fmt_kind) {
                        case FORMAT_PRINTF:
                                check_printf_format(arg, &builtin_table[i]);
diff --git a/lexer.c b/lexer.c
index 3a2a748..daeda8a 100644 (file)
--- a/lexer.c
+++ b/lexer.c
@@ -19,6 +19,7 @@
  */
 #include <config.h>
 
+#include "adt/strutil.h"
 #include "input.h"
 #include "diagnostic.h"
 #include "lexer.h"
@@ -910,7 +911,7 @@ static void parse_line_directive(void)
                         *
                         * currently we're only interested in "3"
                         */
-                       if (strcmp(pp_token.number.number.begin, "3") == 0) {
+                       if (streq(pp_token.number.number.begin, "3")) {
                                lexer_pos.is_system_header = true;
                        }
                        next_pp_token();
index 6d1a959..da35413 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -2611,9 +2611,9 @@ static attribute_t *parse_attribute_ms_property(attribute_t *attribute)
 
                symbol_t **prop;
                symbol_t  *symbol = token.identifier.symbol;
-               if (strcmp(symbol->string, "put") == 0) {
+               if (streq(symbol->string, "put")) {
                        prop = &property->put_symbol;
-               } else if (strcmp(symbol->string, "get") == 0) {
+               } else if (streq(symbol->string, "get")) {
                        prop = &property->get_symbol;
                } else {
                        errorf(HERE, "expected put or get in property declspec");
@@ -2649,7 +2649,7 @@ static attribute_t *parse_microsoft_extended_decl_modifier_single(void)
                for (attribute_kind_t k = ATTRIBUTE_MS_FIRST; k <= ATTRIBUTE_MS_LAST;
                     ++k) {
                        const char *attribute_name = get_attribute_name(k);
-                       if (attribute_name != NULL && strcmp(attribute_name, name) == 0) {
+                       if (attribute_name != NULL && streq(attribute_name, name)) {
                                kind = k;
                                break;
                        }
@@ -3966,7 +3966,7 @@ warn_arg_count:
  */
 static bool is_sym_main(const symbol_t *const sym)
 {
-       return strcmp(sym->string, "main") == 0;
+       return streq(sym->string, "main");
 }
 
 static void error_redefined_as_different_kind(const source_position_t *pos,
@@ -10371,9 +10371,9 @@ static void parse_linkage_specification(void)
 
        linkage_kind_t old_linkage = current_linkage;
        linkage_kind_t new_linkage;
-       if (strcmp(linkage, "C") == 0) {
+       if (streq(linkage, "C")) {
                new_linkage = LINKAGE_C;
-       } else if (strcmp(linkage, "C++") == 0) {
+       } else if (streq(linkage, "C++")) {
                new_linkage = LINKAGE_CXX;
        } else {
                errorf(&pos, "linkage string \"%s\" not recognized", linkage);
index b756e8e..6c56c46 100644 (file)
@@ -19,6 +19,7 @@
  */
 #include <config.h>
 
+#include "adt/strutil.h"
 #include "symbol_table_t.h"
 #include "symbol_t.h"
 #include "token_t.h"
@@ -48,7 +49,7 @@ void init_symbol_table_entry(symbol_t *entry, const char *string)
 #define GetKey(value)              (value)->string
 #define InitData(this,value,key)   ((void)((value) = (ValueType)obstack_alloc(&symbol_obstack, sizeof(symbol_t)), init_symbol_table_entry((value), key)))
 #define Hash(this, key)            hash_string(key)
-#define KeysEqual(this,key1,key2)  (strcmp(key1, key2) == 0)
+#define KeysEqual(this,key1,key2)  (streq(key1, key2))
 #define SetRangeEmpty(ptr,size)    memset(ptr, 0, (size) * sizeof(symbol_table_hash_entry_t))
 #define SCALAR_RETURN
 
index 8caacbf..354d502 100644 (file)
--- a/warning.c
+++ b/warning.c
@@ -119,7 +119,7 @@ void set_warning_opt(const char *const opt)
        }
 
        for (warning_switch_t* i = warning; i != endof(warning); ++i) {
-               if (strcmp(i->name, s) == 0) {
+               if (streq(i->name, s)) {
                        i->state = (i->state & ~off) | on;
                        return;
                }
@@ -128,7 +128,7 @@ void set_warning_opt(const char *const opt)
        if (s[0] == '\0') { // -W is an alias for -Wextra
                goto extra;
        }
-#define OPTX(x)   else if (strcmp(s, x) == 0)
+#define OPTX(x)   else if (streq(s, x))
 #define SET(y)    (void)(warning[y].state = (warning[y].state & ~off) | on)
        OPTX("all") {
                /* Note: this switched on a lot more warnings than gcc's -Wall */
@@ -186,7 +186,7 @@ extra:
        }
 #undef SET
 #undef OPT_X
-       else if (strcmp(opt /* sic */, "error-implicit-function-declaration") == 0) {
+       else if (streq(opt /* sic */, "error-implicit-function-declaration")) {
                /* GCC legacy: This way it only can be activated. */
                warning[WARN_IMPLICIT_FUNCTION_DECLARATION].state = WARN_STATE_ON | WARN_STATE_ERROR;
                return;
index 2cdadb9..f73d8fd 100644 (file)
@@ -56,17 +56,17 @@ static bool is_system_header(const char *fname)
 
 static const char *fix_builtin_names(const char *name)
 {
-       if (strcmp(name, "class") == 0) {
+       if (streq(name, "class")) {
                return "_class";
-       } else if(strcmp(name, "this") == 0) {
+       } else if (streq(name, "this")) {
                return "_this";
-       } else if(strcmp(name, "public") == 0) {
+       } else if (streq(name, "public")) {
                return "_public";
-       } else if(strcmp(name, "protected") == 0) {
+       } else if (streq(name, "protected")) {
                return "_protected";
-       } else if(strcmp(name, "private") == 0) {
+       } else if (streq(name, "private")) {
                return "_private";
-       } else if(strcmp(name, "final") == 0) {
+       } else if (streq(name, "final")) {
                return "_final";
        }
        /* TODO put all reserved names here */
@@ -541,7 +541,7 @@ void write_jna_decls(FILE *output, const translation_unit_t *unit)
                        bool in_limits = false;
                        for (output_limit *limit = output_limits; limit != NULL;
                             limit = limit->next) {
-                           if (strcmp(limit->filename, input_name) == 0) {
+                           if (streq(limit->filename, input_name)) {
                                        in_limits = true;
                                        break;
                                }