Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit33c2da9

Browse files
committed
From: Michael Meskes <meskes@topsystem.de>
Here's the ecpg patch for the local variables bug I reported earlier:
1 parent7d55b1c commit33c2da9

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 alphaversion the preprocessor hasa lot of flaws:
359+
Thisversion the preprocessor hassome 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-
externint debugging;
6+
#include"extern.h"
77

88
#definedbg(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
structvariable
4440
{
4541
char * name;
4642
structECPGtype * type;
43+
int brace_level;
4744
structvariable * next;
4845
};
4946

5047
staticstructvariable * allvariables =NULL;
5148

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

7370

74-
void
71+
staticvoid
7572
new_variable(constchar * name,structECPGtype * type)
7673
{
7774
structvariable * p = (structvariable*)malloc(sizeof(structvariable));
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+
staticvoid
85+
remove_variables(int brace_level)
86+
{
87+
structvariable * 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_EXTERNS_STATIC
162183
%token<tagname>S_UNSIGNEDS_SIGNED
163184
%token<tagname>S_LONGS_SHORTS_INTS_CHARS_FLOATS_DOUBLES_BOOL
164-
%token<tagname>'['']'';'','
185+
%token<tagname>'['']'';'',''{''}'
165186

166187
%type<type>typetype_detailedvarchar_typesimple_typearray_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
staticvoidyyerror(char *error)
361393
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp