@ -69,7 +69,14 @@ char *token_start;
static int state_before_str_start;
static int state_before_str_start;
static int state_before_str_stop;
static int state_before_str_stop;
struct _yy_buffer
/*
* State for handling include files and macro expansion. We use a new
* flex input buffer for each level of include or macro, and create a
* struct _yy_buffer to remember the previous level. There is not a struct
* for the currently active input source; that state is kept in the global
* variables YY_CURRENT_BUFFER, yylineno, and input_filename.
*/
static struct _yy_buffer
{
{
YY_BUFFER_STATE buffer;
YY_BUFFER_STATE buffer;
long lineno;
long lineno;
@ -77,8 +84,6 @@ struct _yy_buffer
struct _yy_buffer *next;
struct _yy_buffer *next;
} *yy_buffer = NULL;
} *yy_buffer = NULL;
static char *old;
/*
/*
* Vars for handling ifdef/elif/endif constructs. preproc_tos is the current
* Vars for handling ifdef/elif/endif constructs. preproc_tos is the current
* nesting depth of such constructs, and stacked_if_value[preproc_tos] is the
* nesting depth of such constructs, and stacked_if_value[preproc_tos] is the
@ -426,6 +431,8 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
%{
%{
/* code to execute during start of each call of yylex() */
/* code to execute during start of each call of yylex() */
char *newdefsymbol = NULL;
token_start = NULL;
token_start = NULL;
%}
%}
@ -961,6 +968,7 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
}
}
{identifier} {
{identifier} {
/* First check to see if it's a define symbol to expand */
if (!isdefine())
if (!isdefine())
{
{
int kwvalue;
int kwvalue;
@ -1153,17 +1161,23 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
yytext[i+1] = '\0';
yytext[i+1] = '\0';
for (ptr = defines; ptr != NULL; ptr2 = ptr, ptr = ptr->next)
/* Find and unset any matching define; should be only 1 */
for (ptr = defines; ptr; ptr2 = ptr, ptr = ptr->next)
{
{
if (strcmp(yytext, ptr->olddef ) == 0)
if (strcmp(yytext, ptr->name ) == 0)
{
{
if (ptr2 == NULL)
free(ptr->value);
defines = ptr->next;
ptr->value = NULL;
else
/* We cannot forget it if there's a cmdvalue */
ptr2->next = ptr->next;
if (ptr->cmdvalue == NULL)
free(ptr->newdef);
{
free(ptr->olddef);
if (ptr2 == NULL)
free(ptr);
defines = ptr->next;
else
ptr2->next = ptr->next;
free(ptr->name);
free(ptr);
}
break;
break;
}
}
}
}
@ -1368,11 +1382,17 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
;
;
yytext[i+1] = '\0';
yytext[i+1] = '\0';
for (defptr = defines;
/* Does a definition exist? */
defptr != NULL &&
for (defptr = defines; defptr; defptr = defptr->next)
strcmp(yytext, defptr->olddef) != 0;
{
defptr = defptr->next)
if (strcmp(yytext, defptr->name) == 0)
/* skip */ ;
{
/* Found it, but is it currently undefined? */
if (defptr->value == NULL)
defptr = NULL; /* pretend it's not found */
break;
}
}
this_active = (defptr ? ifcond : !ifcond);
this_active = (defptr ? ifcond : !ifcond);
stacked_if_value[preproc_tos].active =
stacked_if_value[preproc_tos].active =
@ -1393,7 +1413,7 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
yyterminate();
yyterminate();
}
}
<def_ident>{identifier} {
<def_ident>{identifier} {
old = mm_strdup(yytext);
newdefsymb ol = mm_strdup(yytext);
BEGIN(def);
BEGIN(def);
startlit();
startlit();
}
}
@ -1402,26 +1422,31 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
yyterminate();
yyterminate();
}
}
<def>{space}*";" {
<def>{space}*";" {
struct _defines *ptr, *this ;
struct _defines *ptr;
/* Does it already exist? */
for (ptr = defines; ptr != NULL; ptr = ptr->next)
for (ptr = defines; ptr != NULL; ptr = ptr->next)
{
{
if (strcmp(old, ptr->olddef) == 0)
if (strcmp(newdefsymbol, ptr->name) == 0)
{
{
free(ptr->newdef);
free(ptr->value);
ptr->newdef = mm_strdup(literalbuf);
ptr->value = mm_strdup(literalbuf);
}
/* Don't leak newdefsymbol */
free(newdefsymbol);
break;
}
}
}
if (ptr == NULL)
if (ptr == NULL)
{
{
this = (struct _defines *) mm_alloc(sizeof(struct _defines));
/* Not present, make a new entry */
ptr = (struct _defines *) mm_alloc(sizeof(struct _defines));
/* initial definition */
this->olddef = old;
ptr->name = newdefsymbol;
this->newdef = mm_strdup(literalbuf);
ptr->value = mm_strdup(literalbuf);
this->next = defines;
ptr->cmdvalue = NULL;
this->used = NULL;
ptr->used = NULL;
defines = this;
ptr->next = defines;
defines = ptr;
}
}
BEGIN(C);
BEGIN(C);
@ -1438,6 +1463,7 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
<<EOF>> {
<<EOF>> {
if (yy_buffer == NULL)
if (yy_buffer == NULL)
{
{
/* No more input */
if ( preproc_tos > 0 )
if ( preproc_tos > 0 )
{
{
preproc_tos = 0;
preproc_tos = 0;
@ -1447,16 +1473,20 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
}
}
else
else
{
{
/* Revert to previous input source */
struct _yy_buffer *yb = yy_buffer;
struct _yy_buffer *yb = yy_buffer;
int i;
int i;
struct _defines *ptr;
struct _defines *ptr;
/* Check to see if we are exiting a macro value */
for (ptr = defines; ptr; ptr = ptr->next)
for (ptr = defines; ptr; ptr = ptr->next)
{
if (ptr->used == yy_buffer)
if (ptr->used == yy_buffer)
{
{
ptr->used = NULL;
ptr->used = NULL;
break;
break; /* there can't be multiple matches */
}
}
}
if (yyin != NULL)
if (yyin != NULL)
fclose(yyin);
fclose(yyin);
@ -1681,15 +1711,24 @@ ecpg_isspace(char ch)
return false;
return false;
}
}
static bool isdefine(void)
/*
* If yytext matches a define symbol, begin scanning the symbol's value
* and return true
*/
static bool
isdefine(void)
{
{
struct _defines *ptr;
struct _defines *ptr;
/* is it a define? */
/* is it a define? */
for (ptr = defines; ptr; ptr = ptr->next)
for (ptr = defines; ptr; ptr = ptr->next)
{
{
if (strcmp(yytext, ptr->olddef) == 0 && ptr->used == NULL)
/* notice we do not match anything being actively expanded */
if (strcmp(yytext, ptr->name) == 0 &&
ptr->value != NULL &&
ptr->used == NULL)
{
{
/* Save state associated with the current buffer */
struct _yy_buffer *yb;
struct _yy_buffer *yb;
yb = mm_alloc(sizeof(struct _yy_buffer));
yb = mm_alloc(sizeof(struct _yy_buffer));
@ -1698,10 +1737,17 @@ static bool isdefine(void)
yb->lineno = yylineno;
yb->lineno = yylineno;
yb->filename = mm_strdup(input_filename);
yb->filename = mm_strdup(input_filename);
yb->next = yy_buffer;
yb->next = yy_buffer;
yy_buffer = yb;
ptr->used = yy_buffer = yb;
/* Mark symbol as being actively expanded */
ptr->used = yb;
yy_scan_string(ptr->newdef);
/*
* We use yy_scan_string which will copy the value, so there's
* no need to worry about a possible undef happening while we
* are still scanning it.
*/
yy_scan_string(ptr->value);
return true;
return true;
}
}
}
}
@ -1709,7 +1755,12 @@ static bool isdefine(void)
return false;
return false;
}
}
static bool isinformixdefine(void)
/*
* Handle replacement of INFORMIX built-in defines. This works just
* like isdefine() except for the source of the string to scan.
*/
static bool
isinformixdefine(void)
{
{
const char *new = NULL;
const char *new = NULL;