[cfe-dev] RFC: Easier AST Matching by Default
Dmitri Gribenko via cfe-dev
cfe-dev at lists.llvm.org
Mon Jan 13 08:33:53 PST 2020
On Mon, Jan 13, 2020 at 5:27 PM Ilya Biryukov via cfe-dev <
cfe-dev at lists.llvm.org> wrote:
> Since this popped up, I wanted to add a bit to the point made in the
> syntax trees doc.
>
> Matchers for syntax trees have the following downsides:
> - would incur a maintenance burden,
> - will lack semantic information (at least some of it, e.g. implicit
> casts),
> - may not be as helpful in some use-cases (syntax trees already aim to
> provide an alternative interface to the AST that is simpler to use for some
> use-cases, something that AST matchers also try to do),
> - they incur both runtime and compile-time cost.
>
> However, matchers are also a DSL for pattern-matching the parse tree in
> C++. In this sense they could also be useful for syntax trees.
> Syntax trees are also much more regular than the AST and I believe
> matchers for syntax trees could even be auto-generated, so they can
> potentially be added there in the future.
>
+1, pattern-matching on syntax trees certainly makes sense, and AST
matchers are a nice DSL for that. Therefore, AST Matchers for syntax trees
directly correspond to the goal in the doc by Stephen Kelly:
> Goal: Users should dump ASTs and write matchers which resemble source
code syntax, not semantics
Dmitri
--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200113/88ed8310/attachment.html>
More information about the cfe-dev
mailing list