Skip to content

Commit

Permalink
[IMCC] Improved IMCC line number tracking, especially in macros and o…
Browse files Browse the repository at this point in the history
…ther

places where it's immediately obvious which rule tracks the end of a line.
Fixes TT #1016.  Note that macros have slightly more tests now, because they're
the tricky part.  POD and heredocs may need more testing too.

git-svn-id: https://svn.parrot.org/parrot/trunk@41742 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
chromatic committed Oct 6, 2009
1 parent 1af6044 commit 0d34eaa
Show file tree
Hide file tree
Showing 8 changed files with 756 additions and 1,319 deletions.
20 changes: 12 additions & 8 deletions compilers/imcc/imcc.l
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ SP [ ]

<heredoc2>{EOL} {
/* heredocs have highest priority
* arrange them before all wildcard state matches
*/
* arrange them before all wildcard state matches */

/* Newline in the heredoc. Realloc and cat on. */
IMCC_INFO(interp)->line++;
Expand Down Expand Up @@ -210,6 +209,8 @@ SP [ ]
yy_pop_state(yyscanner);
yy_scan_string(IMCC_INFO(interp)->frames->heredoc_rest, yyscanner);

/* the EOF rule will increment the line number; decrement here */
IMCC_INFO(interp)->line--;
return STRINGC;
}
else {
Expand Down Expand Up @@ -282,9 +283,8 @@ SP [ ]


<INITIAL,emit,macro>^"=cut"{EOL} {
/* this is a stand-alone =cut, but we're
* not in POD mode, so just ignore.
*/
/* this is a stand-alone =cut, but we're not in POD mode, so ignore. */
IMCC_INFO(interp)->line++;
}

<INITIAL,emit,macro>^"=" {
Expand Down Expand Up @@ -521,7 +521,7 @@ SP [ ]
char * const macro_name = mem_sys_strdup(yytext + 1);
int failed = expand_macro(interp, macro_name, yyscanner);
mem_sys_free(macro_name);
if (! failed) {
if (!failed) {
yyless(1);
return DOT;
}
Expand Down Expand Up @@ -989,7 +989,7 @@ read_macro(YYSTYPE *valp, PARROT_INTERP, void *yyscanner)
IMCC_fataly(interp, EXCEPTION_SYNTAX_ERROR, "Macro names must be identifiers");

IMCC_INFO(interp)->cur_macro_name = valp->s;
start_line = IMCC_INFO(interp)->line++;
start_line = IMCC_INFO(interp)->line;

memset(&params, 0, sizeof (params_t));

Expand Down Expand Up @@ -1058,6 +1058,9 @@ read_macro(YYSTYPE *valp, PARROT_INTERP, void *yyscanner)
IMCC_INFO(interp)->macro_buffer = NULL;
IMCC_INFO(interp)->cur_macro_name = NULL;

/* the ENDM rule doesn't set the line number */
IMCC_INFO(interp)->line--;

return MACRO;
}

Expand Down Expand Up @@ -1218,7 +1221,8 @@ expand_macro(PARROT_INTERP, ARGIN(const char *name), void *yyscanner)
}
}

IMCC_INFO(interp)->line = m->line;
/* let the normal EOF rules match line numbers */
IMCC_INFO(interp)->line = m->line - 1;
scan_string(frame, m->expansion, yyscanner);

return 1;
Expand Down
6 changes: 2 additions & 4 deletions compilers/imcc/imcc.y
Original file line number Diff line number Diff line change
Expand Up @@ -2003,7 +2003,7 @@ assignment:
| target '=' un_op var
{ $$ = MK_I(interp, IMCC_INFO(interp)->cur_unit, $3, 2, $1, $4); }
| target '=' var bin_op var
{ IMCC_INFO(interp)->line++; $$ = MK_I(interp, IMCC_INFO(interp)->cur_unit, $4, 3, $1, $3, $5); IMCC_INFO(interp)->line--; }
{ $$ = MK_I(interp, IMCC_INFO(interp)->cur_unit, $4, 3, $1, $3, $5); }
| target '=' var '[' keylist ']'
{ $$ = iINDEXFETCH(interp, IMCC_INFO(interp)->cur_unit, $1, $3, $5); }
| target '[' keylist ']' '=' var
Expand Down Expand Up @@ -2086,9 +2086,7 @@ get_results:

op_assign:
target assign_op var
{
IMCC_INFO(interp)->line++; $$ = MK_I(interp, IMCC_INFO(interp)->cur_unit, $2, 2, $1, $3); IMCC_INFO(interp)->line--;
}
{ $$ = MK_I(interp, IMCC_INFO(interp)->cur_unit, $2, 2, $1, $3); }
;

assign_op:
Expand Down
42 changes: 23 additions & 19 deletions compilers/imcc/imclexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2843,8 +2843,7 @@ YY_RULE_SETUP
#line 175 "compilers/imcc/imcc.l"
{
/* heredocs have highest priority
* arrange them before all wildcard state matches
*/
* arrange them before all wildcard state matches */

/* Newline in the heredoc. Realloc and cat on. */
IMCC_INFO(interp)->line++;
Expand All @@ -2858,7 +2857,7 @@ YY_RULE_SETUP
YY_BREAK
case 3:
YY_RULE_SETUP
#line 190 "compilers/imcc/imcc.l"
#line 189 "compilers/imcc/imcc.l"
{
/* Are we at the end of the heredoc? */
if (STREQ(IMCC_INFO(interp)->heredoc_end, yytext)) {
Expand All @@ -2882,6 +2881,8 @@ YY_RULE_SETUP
yy_pop_state(yyscanner);
yy_scan_string(IMCC_INFO(interp)->frames->heredoc_rest,yyscanner);

/* the EOF rule will increment the line number; decrement here */
IMCC_INFO(interp)->line--;
return STRINGC;
}
else {
Expand All @@ -2898,7 +2899,7 @@ YY_RULE_SETUP
case 4:
/* rule 4 can match eol */
YY_RULE_SETUP
#line 226 "compilers/imcc/imcc.l"
#line 227 "compilers/imcc/imcc.l"
{
yy_pop_state(yyscanner);
yy_push_state(cmt3, yyscanner);
Expand All @@ -2911,25 +2912,25 @@ YY_RULE_SETUP
YY_BREAK
case 5:
YY_RULE_SETUP
#line 236 "compilers/imcc/imcc.l"
#line 237 "compilers/imcc/imcc.l"
{
yy_pop_state(yyscanner);
yy_push_state(cmt4, yyscanner);
}
YY_BREAK
case 6:
YY_RULE_SETUP
#line 241 "compilers/imcc/imcc.l"
#line 242 "compilers/imcc/imcc.l"
{ yy_push_state(cmt2, yyscanner); }
YY_BREAK
case 7:
YY_RULE_SETUP
#line 243 "compilers/imcc/imcc.l"
#line 244 "compilers/imcc/imcc.l"
{ yy_push_state(cmt1, yyscanner); }
YY_BREAK
case 8:
YY_RULE_SETUP
#line 245 "compilers/imcc/imcc.l"
#line 246 "compilers/imcc/imcc.l"
{
IMCC_INFO(interp)->line = atoi(yytext);
yy_pop_state(yyscanner);
Expand All @@ -2940,7 +2941,7 @@ YY_RULE_SETUP
case 9:
/* rule 9 can match eol */
YY_RULE_SETUP
#line 252 "compilers/imcc/imcc.l"
#line 253 "compilers/imcc/imcc.l"
{
yy_pop_state(yyscanner);
IMCC_INFO(interp)->line++;
Expand All @@ -2949,7 +2950,7 @@ YY_RULE_SETUP
case 10:
/* rule 10 can match eol */
YY_RULE_SETUP
#line 257 "compilers/imcc/imcc.l"
#line 258 "compilers/imcc/imcc.l"
{
if (IMCC_INFO(interp)->expect_pasm == 2)
BEGIN(INITIAL);
Expand All @@ -2962,15 +2963,15 @@ YY_RULE_SETUP
YY_BREAK
case 11:
YY_RULE_SETUP
#line 267 "compilers/imcc/imcc.l"
#line 268 "compilers/imcc/imcc.l"
{
yy_push_state(cmt5, yyscanner);
}
YY_BREAK
case 12:
/* rule 12 can match eol */
YY_RULE_SETUP
#line 271 "compilers/imcc/imcc.l"
#line 272 "compilers/imcc/imcc.l"
{
if (IMCC_INFO(interp)->expect_pasm == 2)
BEGIN(INITIAL);
Expand All @@ -2986,11 +2987,10 @@ YY_RULE_SETUP
case 13:
/* rule 13 can match eol */
YY_RULE_SETUP
#line 284 "compilers/imcc/imcc.l"
#line 285 "compilers/imcc/imcc.l"
{
/* this is a stand-alone =cut, but we're
* not in POD mode, so just ignore.
*/
/* this is a stand-alone =cut, but we're not in POD mode, so ignore. */
IMCC_INFO(interp)->line++;
}
YY_BREAK
case 14:
Expand Down Expand Up @@ -3620,7 +3620,7 @@ YY_RULE_SETUP
char * const macro_name = mem_sys_strdup(yytext + 1);
int failed = expand_macro(interp, macro_name, yyscanner);
mem_sys_free(macro_name);
if (! failed) {
if (!failed) {
yyless(1);
return DOT;
}
Expand Down Expand Up @@ -5402,7 +5402,7 @@ read_macro(YYSTYPE *valp, PARROT_INTERP, void *yyscanner)
IMCC_fataly(interp, EXCEPTION_SYNTAX_ERROR, "Macro names must be identifiers");

IMCC_INFO(interp)->cur_macro_name = valp->s;
start_line = IMCC_INFO(interp)->line++;
start_line = IMCC_INFO(interp)->line;

memset(&params, 0, sizeof (params_t));

Expand Down Expand Up @@ -5471,6 +5471,9 @@ read_macro(YYSTYPE *valp, PARROT_INTERP, void *yyscanner)
IMCC_INFO(interp)->macro_buffer = NULL;
IMCC_INFO(interp)->cur_macro_name = NULL;

/* the ENDM rule doesn't set the line number */
IMCC_INFO(interp)->line--;

return MACRO;
}

Expand Down Expand Up @@ -5631,7 +5634,8 @@ expand_macro(PARROT_INTERP, ARGIN(const char *name), void *yyscanner)
}
}

IMCC_INFO(interp)->line = m->line;
/* let the normal EOF rules match line numbers */
IMCC_INFO(interp)->line = m->line - 1;
scan_string(frame, m->expansion, yyscanner);

return 1;
Expand Down
Loading

0 comments on commit 0d34eaa

Please sign in to comment.