From 63a7c90e365874972925e886ed50941f5620bdfe Mon Sep 17 00:00:00 2001 From: fche Date: Fri, 3 Jun 2005 15:54:47 +0000 Subject: [PATCH] 2005-06-03 Frank Ch. Eigler * parse.cxx (scan): Support C and C++ comment styles. * testsuite/parseok/four.stp: Test them some ... * testsuite/parseko/nine.stp: ... and some more. --- ChangeLog | 6 ++++++ main.cxx | 2 +- parse.cxx | 22 +++++++++++++++++++++- testsuite/parseko/nine.stp | 4 ++++ testsuite/parseok/four.stp | 9 ++++++--- 5 files changed, 38 insertions(+), 5 deletions(-) create mode 100755 testsuite/parseko/nine.stp diff --git a/ChangeLog b/ChangeLog index ee3c57314..f7c7e1dbf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2005-06-03 Frank Ch. Eigler + + * parse.cxx (scan): Support C and C++ comment styles. + * testsuite/parseok/four.stp: Test them some ... + * testsuite/parseko/nine.stp: ... and some more. + 2005-06-02 Frank Ch. Eigler * translate.cxx (visit_concatenation, visit_binary_expression): diff --git a/main.cxx b/main.cxx index e9f191bbd..1de145766 100644 --- a/main.cxx +++ b/main.cxx @@ -40,7 +40,7 @@ void usage () cerr << " -p NUM\tStop after pass NUM 1-3" << endl; cerr << " \t(parse, elaborate, translate)" << endl; cerr << " -I DIR\tLook in DIR for additional .stp script files." << endl; - cerr << " -o FILE\tSend translator output to file instead of stdout." << endl; + cerr << " -o FILE\tSend output to file instead of stdout." << endl; // XXX: other options: // -s: safe mode // -d: dump safety-related external references diff --git a/parse.cxx b/parse.cxx index a117d1bcb..2e350b4d2 100644 --- a/parse.cxx +++ b/parse.cxx @@ -253,13 +253,33 @@ lexer::scan () { int c2 = input.peek (); - if (c == '#') // comment to end-of-line + if (c == '#') // shell comment { unsigned this_line = cursor_line; while (input && cursor_line == this_line) input_get (); goto skip; } + else if (c == '/' && c2 == '/') // C++ comment + { + unsigned this_line = cursor_line; + while (input && cursor_line == this_line) + input_get (); + goto skip; + } + else if (c == '/' && c2 == '*') // C comment + { + c2 = input_get (); + unsigned chars = 0; + while (input) + { + chars ++; // track this to prevent "/*/" from being accepted + c = c2; + c2 = input_get (); + if (chars > 1 && c == '*' && c2 == '/') + goto skip; + } + } n->type = tok_operator; n->content = (char) c; diff --git a/testsuite/parseko/nine.stp b/testsuite/parseko/nine.stp new file mode 100755 index 000000000..438824cb3 --- /dev/null +++ b/testsuite/parseko/nine.stp @@ -0,0 +1,4 @@ +#! stap -p1 +probe foo { + /*/ 0 +} diff --git a/testsuite/parseok/four.stp b/testsuite/parseok/four.stp index 39c9ebd4e..9d7a87298 100755 --- a/testsuite/parseok/four.stp +++ b/testsuite/parseok/four.stp @@ -1,7 +1,10 @@ #! stap -p1 probe syscall ("foo").foo.bar , syscall ("bar"), syscall ("*").return -{ - $a = a$a = a$a$ = 0; +{ # no comment + $a = /* comment */ a$a = /**/ a$a$ = 0; // more comment } - +/* empty comment lines */ +/**/ +# +// -- 2.43.5