mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	Applied Zoltan's patch to make ecpg spit out warnings if a local variable hides a global one with the same name.
This commit is contained in:
		@@ -1,7 +1,7 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * functions needed for descriptor handling
 | 
					 * functions needed for descriptor handling
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/descriptor.c,v 1.32 2010/03/09 11:09:45 meskes Exp $
 | 
					 * $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/descriptor.c,v 1.33 2010/04/01 08:41:01 meskes Exp $
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * since descriptor might be either a string constant or a string var
 | 
					 * since descriptor might be either a string constant or a string var
 | 
				
			||||||
 * we need to check for a constant if we expect a constant
 | 
					 * we need to check for a constant if we expect a constant
 | 
				
			||||||
@@ -188,7 +188,7 @@ output_get_descr(char *desc_name, char *index)
 | 
				
			|||||||
				break;
 | 
									break;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		fprintf(yyout, "%s,", get_dtype(results->value));
 | 
							fprintf(yyout, "%s,", get_dtype(results->value));
 | 
				
			||||||
		ECPGdump_a_type(yyout, v->name, v->type, NULL, NULL, NULL, NULL, make_str("0"), NULL, NULL);
 | 
							ECPGdump_a_type(yyout, v->name, v->type, NULL, NULL, NULL, NULL, make_str("0"), NULL, NULL, v->brace_level, -1);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	drop_assignments();
 | 
						drop_assignments();
 | 
				
			||||||
	fputs("ECPGd_EODT);\n", yyout);
 | 
						fputs("ECPGd_EODT);\n", yyout);
 | 
				
			||||||
@@ -293,7 +293,7 @@ output_set_descr(char *desc_name, char *index)
 | 
				
			|||||||
			case ECPGd_length:
 | 
								case ECPGd_length:
 | 
				
			||||||
			case ECPGd_type:
 | 
								case ECPGd_type:
 | 
				
			||||||
				fprintf(yyout, "%s,", get_dtype(results->value));
 | 
									fprintf(yyout, "%s,", get_dtype(results->value));
 | 
				
			||||||
				ECPGdump_a_type(yyout, v->name, v->type, NULL, NULL, NULL, NULL, make_str("0"), NULL, NULL);
 | 
									ECPGdump_a_type(yyout, v->name, v->type, NULL, NULL, NULL, NULL, make_str("0"), NULL, NULL, v->brace_level, -1);
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			default:
 | 
								default:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/type.c,v 1.88 2010/03/09 11:09:45 meskes Exp $ */
 | 
					/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/type.c,v 1.89 2010/04/01 08:41:01 meskes Exp $ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "postgres_fe.h"
 | 
					#include "postgres_fe.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -54,7 +54,7 @@ ECPGstruct_member_dup(struct ECPGstruct_member * rm)
 | 
				
			|||||||
				 * if this array does contain a struct again, we have to
 | 
									 * if this array does contain a struct again, we have to
 | 
				
			||||||
				 * create the struct too
 | 
									 * create the struct too
 | 
				
			||||||
				 */
 | 
									 */
 | 
				
			||||||
				if (rm->type->u.element->type == ECPGt_struct)
 | 
									if (rm->type->u.element->type == ECPGt_struct || rm->type->u.element->type == ECPGt_union)
 | 
				
			||||||
					type = ECPGmake_struct_type(rm->type->u.element->u.members, rm->type->u.element->type, rm->type->u.element->type_name, rm->type->u.element->struct_sizeof);
 | 
										type = ECPGmake_struct_type(rm->type->u.element->u.members, rm->type->u.element->type, rm->type->u.element->type_name, rm->type->u.element->struct_sizeof);
 | 
				
			||||||
				else
 | 
									else
 | 
				
			||||||
					type = ECPGmake_array_type(ECPGmake_simple_type(rm->type->u.element->type, rm->type->u.element->size, rm->type->u.element->counter), rm->type->size);
 | 
										type = ECPGmake_array_type(ECPGmake_simple_type(rm->type->u.element->type, rm->type->u.element->size, rm->type->u.element->counter), rm->type->size);
 | 
				
			||||||
@@ -240,8 +240,44 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type,
 | 
				
			|||||||
				const char *ind_name, struct ECPGtype * ind_type,
 | 
									const char *ind_name, struct ECPGtype * ind_type,
 | 
				
			||||||
				const char *prefix, const char *ind_prefix,
 | 
									const char *prefix, const char *ind_prefix,
 | 
				
			||||||
				char *arr_str_siz, const char *struct_sizeof,
 | 
									char *arr_str_siz, const char *struct_sizeof,
 | 
				
			||||||
				const char *ind_struct_sizeof)
 | 
									const char *ind_struct_sizeof,
 | 
				
			||||||
 | 
									const int brace_level, const int ind_brace_level)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						struct variable *var;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (type->type != ECPGt_descriptor && type->type != ECPGt_sqlda &&
 | 
				
			||||||
 | 
							type->type != ECPGt_char_variable &&
 | 
				
			||||||
 | 
							brace_level >= 0)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							char	   *str;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							str = strdup(name);
 | 
				
			||||||
 | 
							var = find_variable(str);
 | 
				
			||||||
 | 
							free(str);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if ((var->type->type != type->type) ||
 | 
				
			||||||
 | 
								(var->type->type_name && !type->type_name) ||
 | 
				
			||||||
 | 
								(!var->type->type_name && type->type_name) ||
 | 
				
			||||||
 | 
								(var->type->type_name && type->type_name && strcmp(var->type->type_name, type->type_name)))
 | 
				
			||||||
 | 
								mmerror(PARSE_ERROR, ET_WARNING, "variable (%s) is hidden by a local variable of a different type", name);
 | 
				
			||||||
 | 
							else if (var->brace_level != brace_level)
 | 
				
			||||||
 | 
								mmerror(PARSE_ERROR, ET_WARNING, "variable (%s) is hidden by a local variable", name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (ind_name && ind_type && ind_type->type != ECPGt_NO_INDICATOR && ind_brace_level >= 0)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								str = strdup(ind_name);
 | 
				
			||||||
 | 
								var = find_variable(str);
 | 
				
			||||||
 | 
								free(str);
 | 
				
			||||||
 | 
								if ((var->type->type != ind_type->type) ||
 | 
				
			||||||
 | 
									(var->type->type_name && !ind_type->type_name) ||
 | 
				
			||||||
 | 
									(!var->type->type_name && ind_type->type_name) ||
 | 
				
			||||||
 | 
									(var->type->type_name && ind_type->type_name && strcmp(var->type->type_name, ind_type->type_name)))
 | 
				
			||||||
 | 
									mmerror(PARSE_ERROR, ET_WARNING, "indicator variable (%s) is hidden by a local variable of a different type", ind_name);
 | 
				
			||||||
 | 
								else if (var->brace_level != ind_brace_level)
 | 
				
			||||||
 | 
									mmerror(PARSE_ERROR, ET_WARNING, "indicator variable (%s) is hidden by a local variable", ind_name);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	switch (type->type)
 | 
						switch (type->type)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		case ECPGt_array:
 | 
							case ECPGt_array:
 | 
				
			||||||
@@ -503,7 +539,8 @@ ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, char *arrsiz,
 | 
				
			|||||||
						(ind_p != NULL) ? ind_p->name : NULL,
 | 
											(ind_p != NULL) ? ind_p->name : NULL,
 | 
				
			||||||
						(ind_p != NULL) ? ind_p->type : NULL,
 | 
											(ind_p != NULL) ? ind_p->type : NULL,
 | 
				
			||||||
						prefix, ind_prefix, arrsiz, type->struct_sizeof,
 | 
											prefix, ind_prefix, arrsiz, type->struct_sizeof,
 | 
				
			||||||
						(ind_p != NULL) ? ind_type->struct_sizeof : NULL);
 | 
											(ind_p != NULL) ? ind_type->struct_sizeof : NULL,
 | 
				
			||||||
 | 
											-1, -1);
 | 
				
			||||||
		if (ind_p != NULL && ind_p != &struct_no_indicator)
 | 
							if (ind_p != NULL && ind_p != &struct_no_indicator)
 | 
				
			||||||
			ind_p = ind_p->next;
 | 
								ind_p = ind_p->next;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/type.h,v 1.54 2010/03/09 11:09:45 meskes Exp $
 | 
					 * $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/type.h,v 1.55 2010/04/01 08:41:01 meskes Exp $
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
#ifndef _ECPG_PREPROC_TYPE_H
 | 
					#ifndef _ECPG_PREPROC_TYPE_H
 | 
				
			||||||
#define _ECPG_PREPROC_TYPE_H
 | 
					#define _ECPG_PREPROC_TYPE_H
 | 
				
			||||||
@@ -57,7 +57,8 @@ void		ECPGfree_type(struct ECPGtype *);
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
void ECPGdump_a_type(FILE *, const char *, struct ECPGtype *,
 | 
					void ECPGdump_a_type(FILE *, const char *, struct ECPGtype *,
 | 
				
			||||||
				const char *, struct ECPGtype *, const char *,
 | 
									const char *, struct ECPGtype *, const char *,
 | 
				
			||||||
				const char *, char *, const char *, const char *);
 | 
									const char *, char *, const char *, const char *,
 | 
				
			||||||
 | 
									const int, const int);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* A simple struct to keep a variable and its type. */
 | 
					/* A simple struct to keep a variable and its type. */
 | 
				
			||||||
struct ECPGtemp_type
 | 
					struct ECPGtemp_type
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/variable.c,v 1.54 2010/03/09 11:09:45 meskes Exp $ */
 | 
					/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/variable.c,v 1.55 2010/04/01 08:41:01 meskes Exp $ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "postgres_fe.h"
 | 
					#include "postgres_fe.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -22,7 +22,7 @@ new_variable(const char *name, struct ECPGtype * type, int brace_level)
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static struct variable *
 | 
					static struct variable *
 | 
				
			||||||
find_struct_member(char *name, char *str, struct ECPGstruct_member * members, int brace_level)
 | 
					find_struct_member(const char *name, char *str, struct ECPGstruct_member * members, int brace_level)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	char	   *next = strpbrk(++str, ".-["),
 | 
						char	   *next = strpbrk(++str, ".-["),
 | 
				
			||||||
			   *end,
 | 
								   *end,
 | 
				
			||||||
@@ -446,7 +446,8 @@ dump_variables(struct arguments * list, int mode)
 | 
				
			|||||||
	/* Then the current element and its indicator */
 | 
						/* Then the current element and its indicator */
 | 
				
			||||||
	ECPGdump_a_type(yyout, list->variable->name, list->variable->type,
 | 
						ECPGdump_a_type(yyout, list->variable->name, list->variable->type,
 | 
				
			||||||
					list->indicator->name, list->indicator->type,
 | 
										list->indicator->name, list->indicator->type,
 | 
				
			||||||
					NULL, NULL, make_str("0"), NULL, NULL);
 | 
										NULL, NULL, make_str("0"), NULL, NULL,
 | 
				
			||||||
 | 
										list->variable->brace_level, list->indicator->brace_level);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Then release the list element. */
 | 
						/* Then release the list element. */
 | 
				
			||||||
	if (mode != 0)
 | 
						if (mode != 0)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user