Fix #78: Handle C-style comments (/* */) in GAS parser.

svn path=/trunk/yasm/; revision=1633
0.6.0
Peter Johnson 18 years ago
parent 62b74cc2c5
commit 096e2eb79a
  1. 10
      modules/parsers/gas/gas-parser.c
  2. 1
      modules/parsers/gas/gas-parser.h
  3. 24
      modules/parsers/gas/gas-token.re
  4. 3
      modules/parsers/gas/tests/bin/Makefile.inc
  5. 23
      modules/parsers/gas/tests/bin/gas-comment.asm
  6. 1
      modules/parsers/gas/tests/bin/gas-comment.errwarn
  7. 6
      modules/parsers/gas/tests/bin/gas-comment.hex

@ -93,6 +93,16 @@ gas_parser_do_parse(yasm_object *object, yasm_preproc *pp, yasm_arch *a,
yasm_errwarn_propagate(errwarns, parser_gas.rept->startline); yasm_errwarn_propagate(errwarns, parser_gas.rept->startline);
} }
/* Check for ending inside a comment */
if (parser_gas.state == COMMENT) {
yasm_warn_set(YASM_WARN_GENERAL, N_("end of file in comment"));
/* XXX: Minus two to compensate for already having moved past the EOF
* in the linemap.
*/
yasm_errwarn_propagate(errwarns,
yasm_linemap_get_current(parser_gas.linemap)-2);
}
gas_parser_cleanup(&parser_gas); gas_parser_cleanup(&parser_gas);
/* Free locallabel base if necessary */ /* Free locallabel base if necessary */

@ -90,6 +90,7 @@ typedef struct yasm_parser_gas {
Scanner s; Scanner s;
enum { enum {
INITIAL, INITIAL,
COMMENT,
SECTION_DIRECTIVE, SECTION_DIRECTIVE,
INSTDIR INSTDIR
} state; } state;

@ -266,6 +266,8 @@ gas_parser_lex(YYSTYPE *lvalp, yasm_parser_gas *parser_gas)
/* Jump to proper "exclusive" states */ /* Jump to proper "exclusive" states */
switch (parser_gas->state) { switch (parser_gas->state) {
case COMMENT:
goto comment;
case SECTION_DIRECTIVE: case SECTION_DIRECTIVE:
goto section_directive; goto section_directive;
default: default:
@ -478,6 +480,7 @@ scan:
RETURN(ID); RETURN(ID);
} }
"/*" { parser_gas->state = COMMENT; goto comment; }
"#" (any \ [\n])* { goto scan; } "#" (any \ [\n])* { goto scan; }
ws+ { goto scan; } ws+ { goto scan; }
@ -497,6 +500,27 @@ scan:
} }
*/ */
/* C-style comment; nesting not supported */
comment:
SCANINIT();
/*!re2c
/* End of comment */
"*/" { parser_gas->state = INITIAL; goto scan; }
"\n" {
if (parser_gas->save_input)
cursor = save_line(parser_gas, cursor);
RETURN(s->tok[0]);
}
any {
if (cursor == s->eof)
return 0;
goto comment;
}
*/
/* .section directive (the section name portion thereof) */ /* .section directive (the section name portion thereof) */
section_directive: section_directive:
SCANINIT(); SCANINIT();

@ -3,6 +3,9 @@
TESTS += modules/parsers/gas/tests/bin/gas_bin_test.sh TESTS += modules/parsers/gas/tests/bin/gas_bin_test.sh
EXTRA_DIST += modules/parsers/gas/tests/bin/gas_bin_test.sh EXTRA_DIST += modules/parsers/gas/tests/bin/gas_bin_test.sh
EXTRA_DIST += modules/parsers/gas/tests/bin/gas-comment.asm
EXTRA_DIST += modules/parsers/gas/tests/bin/gas-comment.errwarn
EXTRA_DIST += modules/parsers/gas/tests/bin/gas-comment.hex
EXTRA_DIST += modules/parsers/gas/tests/bin/rept-err.asm EXTRA_DIST += modules/parsers/gas/tests/bin/rept-err.asm
EXTRA_DIST += modules/parsers/gas/tests/bin/rept-err.errwarn EXTRA_DIST += modules/parsers/gas/tests/bin/rept-err.errwarn
EXTRA_DIST += modules/parsers/gas/tests/bin/reptempty.asm EXTRA_DIST += modules/parsers/gas/tests/bin/reptempty.asm

@ -0,0 +1,23 @@
# This is a comment
/* So is this */
.byte 0 /* at end of line? */
.byte 0 /* at end of line,
multi-line? */
/* start of line? */ .byte 0
/* What about
a multi-line
comment? -- at start of line?
*/ .byte 0
.byte 0, /* in middle? */ 1
# Illegal; 1 seen on next line
#.byte 0, /* in middle,
#spanning lines? */ 1
/* EOF in comment?

@ -0,0 +1 @@
-:23: warning: end of file in comment
Loading…
Cancel
Save