浏览代码

Implement comment handling in the lexer (with test).

We support both single-line (//) and multi-line (/* ... */) comments
and add a test for this, (trying to stress the rules just a bit by
embedding one comment delimiter into a comment delimited with the
other style, etc.).

To keep the test suite passing we do now discard any output lines from
glcpp that consist only of spacing, (in addition to blank lines as
previously). We also discard any initial whitespace from gcc output.
In neither case should the absence or presence of this whitespace
affect correctness.
tags/mesa-7.9-rc1
Carl Worth 15 年前
父节点
当前提交
2571415d1a
共有 3 个文件被更改,包括 28 次插入2 次删除
  1. 11
    0
      glcpp-lex.l
  2. 15
    0
      tests/063-comments.c
  3. 2
    2
      tests/glcpp-test

+ 11
- 0
glcpp-lex.l 查看文件



%% %%


/* Single-line comments */
"//"[^\n]+\n {
return NEWLINE;
}

/* Multi-line comments */
[/][*]([^*]*[*]+[^/])*[^*]*[*]*[/] {
if (yyextra->space_tokens)
return SPACE;
}

{HASH}if/.*\n { {HASH}if/.*\n {
yyextra->lexing_if = 1; yyextra->lexing_if = 1;
yyextra->space_tokens = 0; yyextra->space_tokens = 0;

+ 15
- 0
tests/063-comments.c 查看文件

/* this is a comment */
// so is this
// */
f = g/**//h;
/*//*/l();
m = n//**/o
+ p;
/* this
comment spans
multiple lines and
contains *** stars
and slashes / *** /
and other stuff.
****/
more code here

+ 2
- 2
tests/glcpp-test 查看文件

for test in *.c; do for test in *.c; do
echo "Testing $test" echo "Testing $test"
../glcpp < $test > $test.glcpp ../glcpp < $test > $test.glcpp
grep -v '^$' < $test.glcpp > $test.out || true
grep -v '^ *$' < $test.glcpp > $test.out || true
gcc -E $test -o $test.gcc gcc -E $test -o $test.gcc
grep -v '^#' < $test.gcc | grep -v '^$' > $test.expected || true
grep -v '^#' < $test.gcc | grep -v '^$' | sed -r -e 's/^ +/ /' > $test.expected || true
diff -u $test.expected $test.out diff -u $test.expected $test.out
done done

正在加载...
取消
保存