S
Scott Meyers
C++ is a very tough language to parse, where by "parse" I mean not just
dealing with its syntax, but also doing the semantic analysis to perform
template instantiation and overload resolution. But I get the sense
that there are now several tools that can address this challenge. My
goal in this post is to find out about tools I may not know about so
that I can look into them.
To clarify what I'm looking for, suppose I'd like to write an "autoizer"
program that, given a C++98 program, inserts use of C++0x's "auto" in
all the places where it doesn't change the program's semantics. For
example, given
int x = 10;
the statement would be rewritten as
auto x = 10;
More interestingly, given
int x = f(a, b, c);
it would be rewritten as
auto x = f(a, b, c);
only if the result of f(a, b, c) is int. If f(a, b, c) returned a type
other than int, the statement would remain unchanged.
Whether a program like autoizer is a good idea is beside the point.
What's interesting is that such a program would require the ability to
parse a C++ program, and, ideally, modify the parsed representation in
place. For autoizer, a good tool would make it easy to find statements
in C++ that define a new named variable and initialize it with an
expression.
Here are candidate tools I know of:
- ROSE ( http://www.rosecompiler.org/ )
- Vivacore ( http://www.viva64.com/en/vivacore-library/ )
- gcc plugins ( http://gcc.gnu.org/wiki/plugins )
- Dedydra ( https://developer.mozilla.org/en/Dehydra - based on gcc plugins)
- Clang ( http://clang.llvm.org/features.html )
Are there others I should be aware of? If you wanted to write something
like autoizer, but you didn't want to write a C++ parser, where would
you start?
Thanks,
Scott
dealing with its syntax, but also doing the semantic analysis to perform
template instantiation and overload resolution. But I get the sense
that there are now several tools that can address this challenge. My
goal in this post is to find out about tools I may not know about so
that I can look into them.
To clarify what I'm looking for, suppose I'd like to write an "autoizer"
program that, given a C++98 program, inserts use of C++0x's "auto" in
all the places where it doesn't change the program's semantics. For
example, given
int x = 10;
the statement would be rewritten as
auto x = 10;
More interestingly, given
int x = f(a, b, c);
it would be rewritten as
auto x = f(a, b, c);
only if the result of f(a, b, c) is int. If f(a, b, c) returned a type
other than int, the statement would remain unchanged.
Whether a program like autoizer is a good idea is beside the point.
What's interesting is that such a program would require the ability to
parse a C++ program, and, ideally, modify the parsed representation in
place. For autoizer, a good tool would make it easy to find statements
in C++ that define a new named variable and initialize it with an
expression.
Here are candidate tools I know of:
- ROSE ( http://www.rosecompiler.org/ )
- Vivacore ( http://www.viva64.com/en/vivacore-library/ )
- gcc plugins ( http://gcc.gnu.org/wiki/plugins )
- Dedydra ( https://developer.mozilla.org/en/Dehydra - based on gcc plugins)
- Clang ( http://clang.llvm.org/features.html )
Are there others I should be aware of? If you wanted to write something
like autoizer, but you didn't want to write a C++ parser, where would
you start?
Thanks,
Scott