Fix #78: Handle C-style comments (/* */) in GAS parser.
authorPeter Johnson <peter@tortall.net>
Wed, 27 Sep 2006 07:02:27 +0000 (07:02 -0000)
committerPeter Johnson <peter@tortall.net>
Wed, 27 Sep 2006 07:02:27 +0000 (07:02 -0000)
svn path=/trunk/yasm/; revision=1633

modules/parsers/gas/gas-parser.c
modules/parsers/gas/gas-parser.h
modules/parsers/gas/gas-token.re
modules/parsers/gas/tests/bin/Makefile.inc
modules/parsers/gas/tests/bin/gas-comment.asm [new file with mode: 0644]
modules/parsers/gas/tests/bin/gas-comment.errwarn [new file with mode: 0644]
modules/parsers/gas/tests/bin/gas-comment.hex [new file with mode: 0644]

index e1a3635f130a8e9075c10e3a20e89712b61804fc..f70e70ab7c3f94b52ca6a70edf95aa8548b27c2a 100644 (file)
@@ -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);
     }
 
+    /* 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);
 
     /* Free locallabel base if necessary */
index c26c939ddd8907c63fc789c12351e098f5991453..f736bb288ede55eb8c5a92636bd2fbf6119881df 100644 (file)
@@ -90,6 +90,7 @@ typedef struct yasm_parser_gas {
     Scanner s;
     enum {
        INITIAL,
+       COMMENT,
        SECTION_DIRECTIVE,
        INSTDIR
     } state;
index bb65ae08041bce6d23b1304d85b0294577bedfb1..08e4d946978a072de8bb14abd85d816fff3e88ab 100644 (file)
@@ -266,6 +266,8 @@ gas_parser_lex(YYSTYPE *lvalp, yasm_parser_gas *parser_gas)
 
     /* Jump to proper "exclusive" states */
     switch (parser_gas->state) {
+       case COMMENT:
+           goto comment;
        case SECTION_DIRECTIVE:
            goto section_directive;
        default:
@@ -478,6 +480,7 @@ scan:
            RETURN(ID);
        }
 
+       "/*"                    { parser_gas->state = COMMENT; goto comment; }
        "#" (any \ [\n])*       { 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:
     SCANINIT();
index 6091c01918cfd36bb22ff8cef6c32ba62910bcb1..93b08f27eadc991b48ec73ab97473e0f1677397d 100644 (file)
@@ -3,6 +3,9 @@
 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-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.errwarn
 EXTRA_DIST += modules/parsers/gas/tests/bin/reptempty.asm
diff --git a/modules/parsers/gas/tests/bin/gas-comment.asm b/modules/parsers/gas/tests/bin/gas-comment.asm
new file mode 100644 (file)
index 0000000..ee68e55
--- /dev/null
@@ -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?
diff --git a/modules/parsers/gas/tests/bin/gas-comment.errwarn b/modules/parsers/gas/tests/bin/gas-comment.errwarn
new file mode 100644 (file)
index 0000000..1fb55a3
--- /dev/null
@@ -0,0 +1 @@
+-:23: warning: end of file in comment
diff --git a/modules/parsers/gas/tests/bin/gas-comment.hex b/modules/parsers/gas/tests/bin/gas-comment.hex
new file mode 100644 (file)
index 0000000..93d7888
--- /dev/null
@@ -0,0 +1,6 @@
+00 
+00 
+00 
+00 
+00 
+01