Explorar o código

Check for duplicate names (function parser)

jp9000 %!s(int64=11) %!d(string=hai) anos
pai
achega
f91b4ef98e
Modificáronse 1 ficheiros con 21 adicións e 1 borrados
  1. 21 1
      libobs/callback/decl.c

+ 21 - 1
libobs/callback/decl.c

@@ -20,7 +20,7 @@
 static inline void err_specifier_exists(struct cf_parser *cfp,
 		const char *storage)
 {
-	cf_adderror(cfp, "'$1' specifier already exists", LEX_WARNING,
+	cf_adderror(cfp, "'$1' specifier already exists", LEX_ERROR,
 			storage, NULL, NULL);
 }
 
@@ -30,6 +30,11 @@ static inline void err_reserved_name(struct cf_parser *cfp, const char *name)
 			name, NULL, NULL);
 }
 
+static inline void err_existing_name(struct cf_parser *cfp, const char *name)
+{
+	cf_adderror(cfp, "'$1' already exists", LEX_ERROR, name, NULL, NULL);
+}
+
 static bool is_in_out_specifier(struct cf_parser *cfp, struct strref *name,
 		uint32_t *type)
 {
@@ -86,6 +91,18 @@ static bool is_reserved_name(const char *str)
 	       (strcmp(str, "return") == 0);
 }
 
+static bool name_exists(struct decl_info *decl, const char *name)
+{
+	for (size_t i = 0; i < decl->params.num; i++) {
+		const char *param_name = decl->params.array[i].name;
+
+		if (strcmp(name, param_name) == 0)
+			return true;
+	}
+
+	return false;
+}
+
 static int parse_param(struct cf_parser *cfp, struct decl_info *decl)
 {
 	struct strref      ref;
@@ -118,6 +135,9 @@ static int parse_param(struct cf_parser *cfp, struct decl_info *decl)
 	if (code != PARSE_SUCCESS)
 		return code;
 
+	if (name_exists(decl, param.name))
+		err_existing_name(cfp, param.name);
+
 	if (is_reserved_name(param.name))
 		err_reserved_name(cfp, param.name);