#include <stdarg.h>
#include <stdbool.h>
+#include "adt/strutil.h"
#include "parser.h"
#include "diagnostic.h"
#include "format_check.h"
return result;
}
-/**
- * compare two string, ignoring double underscores on the second.
- */
-static int strcmp_underscore(const char *s1, const char *s2)
-{
- if (s2[0] == '_' && s2[1] == '_') {
- size_t len2 = strlen(s2);
- size_t len1 = strlen(s1);
- if (len1 == len2-4 && s2[len2-2] == '_' && s2[len2-1] == '_') {
- return strncmp(s1, s2+2, len2-4);
- }
- }
-
- return strcmp(s1, s2);
-}
-
static attribute_t *allocate_attribute_zero(attribute_kind_t kind)
{
attribute_t *attribute = allocate_ast_zero(sizeof(*attribute));
}
const char *attribute_name = get_attribute_name(kind);
- if (attribute_name != NULL
- && strcmp_underscore(attribute_name, name) == 0)
+ if (attribute_name != NULL && streq_underscore(attribute_name, name))
break;
}
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");
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;
}
*/
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,
type_t *const type = skip_typeref(entity->typedefe.type);
type_t *const prev_type
= skip_typeref(previous_entity->typedefe.type);
- /* gcc extension: redef in system headers is allowed */
- if ((pos->is_system_header || ppos->is_system_header)
- && types_compatible(type, prev_type))
- goto finish;
- /* c++ allows double typedef if they are identical
- * (after skipping typedefs) */
- if ((c_mode & _CXX) && type == prev_type)
- goto finish;
+ if (c_mode & _CXX) {
+ /* C++ allows double typedef if they are identical
+ * (after skipping typedefs) */
+ if (type == prev_type)
+ goto finish;
+ } else {
+ /* GCC extension: redef in system headers is allowed */
+ if ((pos->is_system_header || ppos->is_system_header) &&
+ types_compatible(type, prev_type))
+ goto finish;
+ }
errorf(pos, "redefinition of '%N' (declared %P)",
entity, ppos);
goto finish;
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);