[cfe-dev] Function body type
Douglas Gregor
dgregor at apple.com
Sun Apr 26 08:46:03 PDT 2009
On Apr 26, 2009, at 8:19 AM, Sebastian Redl wrote:
> Hi,
>
> Small problem: the type of a function's body is currently
> CompoundStmt.
> However, in C++ we have function-try-blocks:
>
> void f() try {
> // things that could throw
> } catch(something) {
> // ...
> } catch(...) {
> // ...
> }
>
> The obvious solution here is to change FunctionDecl so that its body
> can
> be either a CompoundStmt or a CXXTryStmt (by having getBody() return
> either a Stmt* or a PointerVariant). However, this change is quite
> disrupting to many, many components.
I think using Stmt* is perfectly reasonable. I am not at all worried
about this change touching many components; it's a mechanical
transformation that is unlikely to break anything and it is the right
thing to do.
It probably makes sense to add a
CompoundStmt *getCompoundBody(ASTContext &Context, const
FunctionDecl *&Definition) {
return dyn_cast_or_null<CompoundStmt>(getBody(Context,
Definition));
}
so that we've encapsulated the dyn_cast_or_null into a single place.
> The alternative is to represent such functions as if they were
> written as
>
> void f() {
> try { .... } ...
> }
>
> There exists a difference in semantics for constructors and
> destructors
> only (where a function-try-block covers base and member
> initializers/destructors, whereas a try-block does not), which could
> be
> stored in a flag in those functions. But I don't like this workaround.
I don't like this workaround, either. We want the AST to describe the
syntax and semantics naturally, and this kind of flag would really
confuse the issue.
- Doug
More information about the cfe-dev
mailing list