[cfe-dev] parse C++ throw
Mike Stump
mrs at apple.com
Mon Feb 25 15:37:30 PST 2008
On Feb 25, 2008, at 2:45 PM, Chris Lattner wrote:
> +/* -*- indent-tabs-mode:nil; -*- */
>
> Please don't do this.
FIxed.
> + class CXXThrowExpr : public Expr {
> ...
> + virtual SourceRange getSourceRange() const {
> + return SourceRange(ThrowLoc, getSubExpr()-
> >getSourceRange().getEnd());
> + }
>
> If getSubExpr() is null, this should return SourceRange(ThrowLoc,
> ThrowLoc).
Ah, yes, of course. Fixed.
> +++ ./AST/StmtPrinter.cpp 2008-02-25 13:35:57.000000000 -0800
> @@ -780,6 +780,12 @@ void StmtPrinter::VisitCXXBoolLiteralExp
> OS << (Node->getValue() ? "true" : "false");
> }
>
> +void StmtPrinter::VisitCXXThrowExpr(CXXThrowExpr *Node) {
> + OS << "throw ";
> + if (Node->getSubExpr())
> + PrintExpr(Node->getSubExpr());
>
> It would be slightly nicer to not print the space after the throw if
> subexpr is null.
Yeah, I thought about doing that when I first implemented it and
decided against worrying about it as it didn't seem as bad as the
extra {} in extern "C" handling. But, it is easy, localized and
doesn't require any more data in the AST to do it, sooo.... Fixed.
>> I also added a FIXME for handling throw when not followed by a ';'
>> nor an assignment-expression. Something parser generators do
>> automagically for us, but something we have to compute. Do we have
>> a tentative parse system yet or some other easy way to do this?
>> [ I think I know the answer, I bet not. ]
>
> The fixme is fine for a first step. However, it would be better to
> eventually add a predicate that determines whether a token is the
> start of an expression.
Agreed.
> I don't think there are any cases where a declaration is allowed
> after a throw,
You mean like this:
throw int(1);
? Yup, that's valid.
> so this predicate should be relatively straight-forward, something
> like Parser::isDeclarationSpecifier().
>
> I agree this is somewhat ugly, but it could be worse
Just wait, we'll get there.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: eh-1a.diffs
Type: application/octet-stream
Size: 7713 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20080225/9f7146fb/attachment.obj>
-------------- next part --------------
More information about the cfe-dev
mailing list