Skip to content

Commit 33c2da9

Browse files
committed
From: Michael Meskes <meskes@topsystem.de>
Here's the ecpg patch for the local variables bug I reported earlier:
1 parent 7d55b1c commit 33c2da9

File tree

4 files changed

+51
-19
lines changed

4 files changed

+51
-19
lines changed

src/interfaces/ecpg/TODO

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,5 @@ could be realised in a script.
4444

4545
Now comes my list (MM):
4646

47-
Ecpg should remove variables from its list as soon as they are undefined and
48-
not rely on cc to report an error.
49-
5047
Variable definitions containing static/volatile have to be possible.
5148

src/interfaces/ecpg/doc/ecpg.texinfo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ you are not interested in how it really works, skip this chapter.
356356
@comment node-name, next, previous, up
357357
@section To do list
358358

359-
In the alpha version the preprocessor has a lot of flaws:
359+
This version the preprocessor has some flaws:
360360
@table @asis
361361

362362
@item Preprocessor output

src/interfaces/ecpg/preproc/pgc.l

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "type.h"
44
#include "y.tab.h"
55

6-
extern int debugging;
6+
#include "extern.h"
77

88
#define dbg(arg) if (debugging) fprintf(stderr, "DEBUG, %d: %s\n", yylineno, #arg);
99
%}
@@ -56,7 +56,7 @@ int { dbg(S_INT); return S_INT; }
5656
char { dbg(S_CHAR); return S_CHAR; }
5757
float { dbg(S_FLOAT); return S_FLOAT; }
5858
double { dbg(S_DOUBLE); return S_DOUBLE; }
59-
bool { dbg(S_BOOL); return S_BOOL; }
59+
bool { dbg(S_BOOL); return S_BOOL; }
6060
6161
{string} { dbg(SQL_STRING); return SQL_STRING; }
6262
<SQL>{ws} ;
@@ -97,6 +97,8 @@ bool { dbg(S_BOOL); return S_BOOL; }
9797
"]" { dbg(]); return ']'; }
9898
";" { dbg(;); return ';'; }
9999
"," { dbg(komma); return ','; }
100+
\{ { dbg(blockstart); return '{'; }
101+
\} { dbg(blockend); return'}'; }
100102
101103
<SQL>":" { dbg(:); return ':'; }
102104
@@ -106,6 +108,7 @@ bool { dbg(S_BOOL); return S_BOOL; }
106108
void
107109
lex_init(void)
108110
{
111+
braces_open = 0;
109112
BEGIN C;
110113
}
111114

src/interfaces/ecpg/preproc/preproc.y

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,24 @@ output_line_number()
2929
/*
3030
* Handling of the variables.
3131
*/
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
4135
*/
36+
int braces_open;
37+
4238
/* This is a linked list of the variable names and types. */
4339
struct variable
4440
{
4541
char * name;
4642
struct ECPGtype * type;
43+
int brace_level;
4744
struct variable * next;
4845
};
4946

5047
static struct variable * allvariables = NULL;
5148

52-
struct variable *
49+
static struct variable *
5350
find_variable(char * name)
5451
{
5552
struct variable * p;
@@ -71,18 +68,42 @@ find_variable(char * name)
7168
}
7269

7370

74-
void
71+
static void
7572
new_variable(const char * name, struct ECPGtype * type)
7673
{
7774
struct variable * p = (struct variable*) malloc(sizeof(struct variable));
7875

7976
p->name = strdup(name);
8077
p->type = type;
78+
p->brace_level = braces_open;
8179

8280
p->next = allvariables;
8381
allvariables = p;
8482
}
8583

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+
86107

87108
/*
88109
* Here are the variables that need to be handled on every request.
@@ -161,7 +182,7 @@ dump_variables(struct arguments * list)
161182
%token <tagname> S_EXTERN S_STATIC
162183
%token <tagname> S_UNSIGNED S_SIGNED
163184
%token <tagname> S_LONG S_SHORT S_INT S_CHAR S_FLOAT S_DOUBLE S_BOOL
164-
%token <tagname> '[' ']' ';' ','
185+
%token <tagname> '[' ']' ';' ',' '{' '}'
165186

166187
%type <type> type type_detailed varchar_type simple_type array_type
167188
%type <symbolname> symbol
@@ -184,7 +205,9 @@ statement : sqldeclaration
184205
| sqlcommit
185206
| sqlrollback
186207
| sqlstatement
187-
| cthing;
208+
| cthing
209+
| blockstart
210+
| blockend;
188211

189212
sqldeclaration : sql_startdeclare
190213
variable_declarations
@@ -356,6 +379,15 @@ both_anything : S_LENGTH | S_VARCHAR | S_VARCHAR2
356379
| '[' | ']' | ','
357380
| S_ANYTHING;
358381

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+
}
359391
%%
360392
static void yyerror(char * error)
361393
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy