[cfe-dev] Tentative typeid Parser/AST implementation
Sebastian Redl
sebastian.redl at getdesigned.at
Mon Nov 10 14:48:44 PST 2008
Doug Gregor wrote:
> Hi Sebastian,
>
> On Sun, Nov 9, 2008 at 11:00 AM, Sebastian Redl
> <sebastian.redl at getdesigned.at> wrote:
>
>> Attached patch implements parsing and AST support for typeid. It's not
>> complete in that the type of a typeid expression is const void instead of
>> const std::type_info, but otherwise everything should be correct. However,
>> since this is my first big change of the parser and AST, I might well have
>> overlooked something.
>>
>
> Great! Some comments follow:
>
Thanks.
> +class CXXTypeidExpr : public Expr {
>
> Please provide documentation for this expression type, along with an
> example of C++ code where it would show up.
>
Done.
> +public:
> + enum OperandKind {
> + OpType,
> + OpExpr
> + };
> +
> +private:
> + OperandKind OpKind;
>
> Why not just have a single bit:
>
> bool OperandIsExpression : 1;
>
> ?
>
Done.
> +CXXTypeidExpr*
> +CXXTypeidExpr::CreateImpl(llvm::Deserializer& D, ASTContext& C) {
> + QualType Ty = QualType::ReadVal(D);
> + OperandKind OpKind = static_cast<OperandKind>(OpKind);
>
> Something isn't right here... the argument to the static_cast should
> be an integer value read from D, right?
>
Right. Fixed while rewriting to use a single bit.
> + if (Tok.is(tok::r_paren))
> + RParenLoc = ConsumeParen();
> + else
> + MatchRHSPunctuation(tok::r_paren, LParenLoc);
>
> I believe this can just be:
>
> RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
>
> (This happens twice in ParseCXXTypeid)
>
I copied the code from ParseParenExpression.
Done.
Here's an updated patch. It now looks up std::type_info and fails if it
can't find it. This means that the type of the expression is an lvalue
of type const std::type_info, as it should be. Semantic checking is thus
complete.
Sebastian
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: typeid.patch
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20081110/28f383fe/attachment.ksh>
More information about the cfe-dev
mailing list