@@ -29,27 +29,24 @@ output_line_number()
29
29
/*
30
30
* Handling of the variables.
31
31
*/
32
- /* Since we don't want to keep track of where the functions end we just
33
- * have a list of functions that we search in, most reasently defined
34
- * function. This won't work if we use block scope for variables with the
35
- * same name but different types but in all other cases the c-compiler will
36
- * signal an error (hopefully).
37
- *
38
- * This list is leaked on program exit. This is because I don't think it is
39
- * important enough to spend the extra ten minutes to write the function that
40
- * deletes it. It would be another thing if I would have written in C++.
32
+
33
+ /*
34
+ * brace level counter
41
35
*/
36
+ int braces_open;
37
+
42
38
/* This is a linked list of the variable names and types. */
43
39
struct variable
44
40
{
45
41
char * name;
46
42
struct ECPGtype * type;
43
+ int brace_level;
47
44
struct variable * next;
48
45
};
49
46
50
47
static struct variable * allvariables = NULL ;
51
48
52
- struct variable *
49
+ static struct variable *
53
50
find_variable (char * name)
54
51
{
55
52
struct variable * p;
@@ -71,18 +68,42 @@ find_variable(char * name)
71
68
}
72
69
73
70
74
- void
71
+ static void
75
72
new_variable (const char * name, struct ECPGtype * type)
76
73
{
77
74
struct variable * p = (struct variable *) malloc (sizeof (struct variable ));
78
75
79
76
p->name = strdup (name);
80
77
p->type = type;
78
+ p->brace_level = braces_open;
81
79
82
80
p->next = allvariables;
83
81
allvariables = p;
84
82
}
85
83
84
+ static void
85
+ remove_variables (int brace_level)
86
+ {
87
+ struct variable * p, *prev;
88
+
89
+ for (p = prev = allvariables; p; p = p->next )
90
+ {
91
+ if (p->brace_level >= brace_level)
92
+ {
93
+ /* remove it */
94
+ if (p == allvariables)
95
+ prev = allvariables = p->next ;
96
+ else
97
+ prev->next = p->next ;
98
+
99
+ free (p);
100
+ p = prev;
101
+ }
102
+ else
103
+ prev = p;
104
+ }
105
+ }
106
+
86
107
87
108
/*
88
109
* Here are the variables that need to be handled on every request.
@@ -161,7 +182,7 @@ dump_variables(struct arguments * list)
161
182
%token <tagname> S_EXTERN S_STATIC
162
183
%token <tagname> S_UNSIGNED S_SIGNED
163
184
%token <tagname> S_LONG S_SHORT S_INT S_CHAR S_FLOAT S_DOUBLE S_BOOL
164
- %token <tagname> ' [' ' ]' ' ;' ' ,'
185
+ %token <tagname> ' [' ' ]' ' ;' ' ,' ' { ' ' } '
165
186
166
187
%type <type> type type_detailed varchar_type simple_type array_type
167
188
%type <symbolname> symbol
@@ -184,7 +205,9 @@ statement : sqldeclaration
184
205
| sqlcommit
185
206
| sqlrollback
186
207
| sqlstatement
187
- | cthing ;
208
+ | cthing
209
+ | blockstart
210
+ | blockend ;
188
211
189
212
sqldeclaration : sql_startdeclare
190
213
variable_declarations
@@ -356,6 +379,15 @@ both_anything : S_LENGTH | S_VARCHAR | S_VARCHAR2
356
379
| ' [' | ' ]' | ' ,'
357
380
| S_ANYTHING ;
358
381
382
+ blockstart : ' {' {
383
+ braces_open++;
384
+ fwrite (yytext, yyleng, 1 , yyout);
385
+ }
386
+
387
+ blockend : ' }' {
388
+ remove_variables (braces_open--);
389
+ fwrite (yytext, yyleng, 1 , yyout);
390
+ }
359
391
%%
360
392
static void yyerror (char * error )
361
393
{
0 commit comments