[cfe-commits] [PATCH] Implement AST dumper for Decls

Richard Smith richard at metafoo.co.uk
Tue Oct 2 14:27:31 PDT 2012


On Tue, Oct 2, 2012 at 9:37 AM, Dmitri Gribenko <gribozavr at gmail.com> wrote:

> On Tue, Oct 2, 2012 at 7:22 PM, Alexander Kornienko <alexfh at google.com>
> wrote:
> > Let's put it this way: having a way to use "previous line" or "current
> line
> > + offset" variable in FileCheck, and having a better FileCheck
> performance
> > in debug mode, what would you prefer?
> >
> > TEST(StmtDumper, TestDeclStmt) {
> >   ASSERT_TRUE(DumpedStmtCXX98Matches(
> >     "void A() {\n"
> >     "  int a = 1, b;\n"
> >     "}",
> >     "A",
> >     "(DeclStmt 0xXXXXXXXX <input.cc:2:3, col:15>\n"
> >     "  (VarDecl 0xXXXXXXXX <col:3, col:11> a 'int'\n"
> >     "    (IntegerLiteral 0xXXXXXXXX <col:11> 'int' 1))\n"
> >     "  (VarDecl 0xXXXXXXXX <col:3, col:14> b 'int'))\n"));
> > }
> >
> > or
> >
> > // RUN: clang_cc1 -ast-dump --std=c++98 -DTEST33 %s | FileCheck
> > --strict-whitespace --check-prefix CHECK33 %s
> > #ifdef TEST33
> > void A() {
> > // CHECK33: {{^}}(DeclStmt 0x{{........}}
> <input.cc:[[__LINE_MINUS_1__]]:3,
> > col:15>
> >   int a = 1, b;
> > // CHECK33-NEXT: {{^  }}(VarDecl 0x{{........}} <col:3, col:11> a
> 'int'{{$}}
> > // CHECK33-NEXT: {{^    }}(IntegerLiteral 0x{{........}} <col:11> 'int'
> > 1)){{$}}
> > // CHECK33-NEXT: {{^  }}(VarDecl 0x{{........}} <col:3, col:14> b
> > 'int')){{$}}
> > }
> > #endif
>
> I would prefer the first one and here's why:
>
> 1. Obviously, it is smaller (less text), thus easier to parse.
> 2. In FileCheck one has to do all this escaping and regex dances for
> every line.  In the first approach, it can be abstracted away.
> 3. (a general FileCheck weakness) CHECKXX prefixes should be matched
> between RUN lines and CHECK lines.  It is not a big issue if the file
> has a few different CHECKXX prefixes, but it starts to matter if we
> introduce this kind of isolation into tests and will have lots of
> different prefixes.
>

I prefer the FileCheck approach. I would expect it to be more familiar to
most LLVM and Clang developers, and doesn't require learning another
matching language (0xXXXXXXXX handling, etc). Also, it allows us to easily
write tests which only match those bits of the output we care about, so we
don't have to update a pile of tests when we change which details get
dumped (for instance, I would suggest not matching source locations unless
they're actually what you're testing for).

Also, lit-based tests are a whole lot easier to work with than the gtest
tests. It's trivial to run lit on an individual test file, and to run clang
on the code in the test to find out what output the AST dump is actually
producing. And I don't need to rebuild when I'm hacking on the tests.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121002/8f0d6381/attachment.html>


More information about the cfe-commits mailing list