[cfe-dev] Tentative typeid Parser/AST implementation

Doug Gregor doug.gregor at gmail.com
Mon Nov 10 06:58:42 PST 2008


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:

+class CXXTypeidExpr : public Expr {

Please provide documentation for this expression type, along with an
example of C++ code where it would show up.

+public:
+  enum OperandKind {
+    OpType,
+    OpExpr
+  };
+
+private:
+  OperandKind OpKind;

Why not just have a single bit:

  bool OperandIsExpression : 1;

?

+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?

+    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)

With those tweaks, this patch is okay. Thanks!

  - Doug



More information about the cfe-dev mailing list