summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2020-11-10 06:55:22 -0500
committerEric S. Raymond <esr@thyrsus.com>2020-11-10 06:55:22 -0500
commit87686ff2fbb94978f8c8bf9dc79284bfcd8343a1 (patch)
tree0769d5c652b82596ade586429aa0dcbf369b203f
parent9b68eb3634f1b9edc9e7d35f932661d0ba2a7e7c (diff)
downloadflex-git-87686ff2fbb94978f8c8bf9dc79284bfcd8343a1.tar.gz
Successful elimination of preprocessor dependencies fromm C99 skeleton.
There's only one left. in the prefix code. We leave that in place because ity will be needed if we ever want to replace the default C back end with C99.
-rw-r--r--src/c99-flex.skl41
-rw-r--r--src/scan.l26
-rw-r--r--tests/lineno_c99.l4
3 files changed, 45 insertions, 26 deletions
diff --git a/src/c99-flex.skl b/src/c99-flex.skl
index 88947fe..83dcabd 100644
--- a/src/c99-flex.skl
+++ b/src/c99-flex.skl
@@ -32,6 +32,8 @@ m4_define([[M4_PROPERTY_SOURCE_SUFFIX]], [[.c]])
m4_define([[M4_PROPERTY_TRACE_LINE_REGEXP]], [[^#line ([0-9]+) "(.*)"]])
m4_define([[M4_PROPERTY_TRACE_LINE_TEMPLATE]], [[#line %d "%s"]])
m4_define([[M4_PROPERTY_CONTEXT_ARG]], [[yyscanner]])
+m4_define([[M4_PROPERTY_CONTEXT_FORMAT]], [[yyscanner->%s_r]])
+m4_define([[M4_PROPERTY_BUFFERSTACK_CONTEXT_FORMAT]], [[yyscanner->yy_buffer_stack[yyscanner->yy_buffer_stack_top]->bs_%s]])
%# Macro hooks used by Flex code generators start here
m4_define([[M4_HOOK_INT32]], [[int32_t]])
@@ -1113,19 +1115,6 @@ static void yybumpline( yyscan_t yyscanner) {
yyscanner->yy_buffer_stack[yyscanner->yy_buffer_stack_top]->bs_yycolumn=0;
}
-/* START access macros for use in actions */
-
-#define yyin yyscanner->yyin_r
-#define yyout yyscanner->yyout_r
-#define yyextra yyscanner->yyextra_r
-#define yyleng yyscanner->yyleng_r
-#define yytext yyscanner->yytext_r
-#define yylineno (yyscanner->yy_buffer_stack[yyscanner->yy_buffer_stack_top]->bs_yylineno)
-#define yycolumn (yyscanner->yy_buffer_stack[yyscanner->yy_buffer_stack_top]->bs_yycolumn)
-#define yyflexdebug yyscanner->yyflexdebug_r
-
-/* END access macros for use in actions */
-
m4_ifdef([[M4_MODE_YYMORE_USED]], [[
m4_ifdef( [[M4_MODE_YYTEXT_IS_ARRAY]], [[
void yymore(yyscan_t yyscanner) {yyscanner->yy_more_offset = strlen(yyscanner->yytext_r);}
@@ -1456,7 +1445,7 @@ m4_define([[M4_YYL_BASE]], [[m4_ifdef([[M4_MODE_YYMORE_USED]],
do_action: /* This label is used only to access EOF actions. */
m4_ifdef([[M4_MODE_DEBUG]], [[
- if ( yyflexdebug ) {
+ if ( yyscanner->yyflexdebug_r ) {
if ( yy_act == 0 ) {
fprintf( stderr, "--scanner backing up\n" );
} else if ( yy_act < YY_NUM_RULES ) {
@@ -2325,11 +2314,12 @@ m4_ifdef( [[M4_YY_NO_GET_LINENO]],,
* @param yyscanner The scanner object.
*/
int yyget_lineno (yyscan_t yyscanner) {
+ yybuffer cb = yy_current_buffer(yyscanner);
- if (yy_current_buffer(yyscanner) == NULL) {
+ if (cb == NULL) {
return 0;
}
- return yylineno;
+ return cb->bs_yylineno;
}
]])
@@ -2339,11 +2329,12 @@ m4_ifdef( [[M4_YY_NO_GET_COLUMN]],,
* @param yyscanner The scanner object.
*/
int yyget_column (yyscan_t yyscanner) {
+ yybuffer cb = yy_current_buffer(yyscanner);
- if (yy_current_buffer(yyscanner) == NULL) {
+ if (cb == NULL) {
return 0;
}
- return yycolumn;
+ return cb->bs_yycolumn;
}
]])
@@ -2407,12 +2398,13 @@ m4_ifdef( [[M4_YY_NO_SET_LINENO]],,
* @param yyscanner The scanner object.
*/
void yyset_lineno(int _line_number, yyscan_t yyscanner) {
+ yybuffer cb = yy_current_buffer(yyscanner);
/* lineno is only valid if an input buffer exists. */
- if (yy_current_buffer(yyscanner) == NULL ) {
+ if (cb == NULL ) {
yypanic( "yyset_lineno called with no buffer", yyscanner );
}
- yylineno = _line_number;
+ cb->bs_yylineno = _line_number;
}
]])
@@ -2423,12 +2415,13 @@ m4_ifdef( [[M4_YY_NO_SET_COLUMN]],,
* @param yyscanner The scanner object.
*/
void yyset_column(int _column_no, yyscan_t yyscanner) {
+ yybuffer cb = yy_current_buffer(yyscanner);
/* column is only valid if an input buffer exists. */
- if (yy_current_buffer(yyscanner) == NULL ) {
+ if (cb == NULL ) {
yypanic( "yyset_column called with no buffer", yyscanner );
}
- yycolumn = _column_no;
+ cb->bs_yycolumn = _column_no;
}
]])
@@ -2456,14 +2449,14 @@ void yyset_out( FILE * _out_str, yyscan_t yyscanner) {
m4_ifdef( [[M4_YY_NO_GET_DEBUG]],,
[[
int yyget_debug (yyscan_t yyscanner) {
- return yyflexdebug;
+ return yyscanner->yyflexdebug_r;
}
]])
m4_ifdef( [[M4_YY_NO_SET_DEBUG]],,
[[
void yyset_debug(int _bdebug, yyscan_t yyscanner) {
- yyflexdebug = _bdebug ;
+ yyscanner->yyflexdebug_r = _bdebug ;
}
]])
diff --git a/src/scan.l b/src/scan.l
index 02220e2..87c0d47 100644
--- a/src/scan.l
+++ b/src/scan.l
@@ -150,6 +150,7 @@ FUNARGS [^)]*
%{
void context_call(char *);
+void context_member(char *, const char *);
#undef yyreject
%}
%%
@@ -969,6 +970,18 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */
add_action(yytext);
add_action("[""[");
}
+ yyin|yyout|yyextra|yyleng|yytext|yyflexdebug {
+ if (ctrl.rewrite)
+ context_member(yytext, "M4_PROPERTY_CONTEXT_FORMAT");
+ else
+ ACTION_ECHO;
+ }
+ yylineno|yycolumn {
+ if (ctrl.rewrite)
+ context_member(yytext, "M4_PROPERTY_BUFFERSTACK_CONTEXT_FORMAT");
+ else
+ ACTION_ECHO;
+ }
[^[:Alpha:]_{}""''/\n\[\]]+ ACTION_ECHO;
{NAME} ACTION_ECHO;
"'"([^''\\\n]|\\.)"'" ACTION_ECHO; /* character constant */
@@ -1103,3 +1116,16 @@ void context_call(char *txt) {
add_action(")");
}
}
+
+void context_member(char *txt, const char *prop) {
+ const char *context_format = skel_property(prop);
+
+ /* if there's no such property, simply pass through */
+ if (context_format == NULL) {
+ add_action(txt);
+ } else {
+ char buf[128];
+ snprintf(buf, sizeof(buf), context_format, txt);
+ add_action(buf);
+ }
+}
diff --git a/tests/lineno_c99.l b/tests/lineno_c99.l
index be46e90..11d402c 100644
--- a/tests/lineno_c99.l
+++ b/tests/lineno_c99.l
@@ -50,8 +50,8 @@ DIGIT [[:digit:]]
- directly modifying yylineno.
*/
-"yylineno++" yylineno++;
-"yylineno--" yylineno--;
+"yylineno--" --yylineno;
+"yylineno++" ++yylineno;
[[:blank:]]+
{WORD}
{DIGIT}+(\n{DIGIT}+)*