[cfe-commits] r40631 - in /cfe/trunk: AST/ASTContext.cpp AST/Type.cpp Parse/DeclSpec.cpp Parse/ParseDecl.cpp Sema/SemaExpr.cpp Sema/SemaType.cpp clang.xcodeproj/project.pbxproj include/clang/AST/ASTContext.h include/clang/AST/Type.h include/clang/Parse/DeclSpec.h include/clang/Parse/Parser.h test/Parser/typeof.c

Chris Lattner clattner at apple.com
Tue Jul 31 16:44:22 PDT 2007


> Add parsing and AST support for GNU "typeof".
> Many small changes to lot's of files.
> Still some FIXME's, however the basic support is in place.

Cool.


>
> +QualType ASTContext::getTypeOfType(Expr *tofExpr) {

Should this be named getTypeOfExpr ?

> +  QualType Canonical = tofExpr->getType().getCanonicalType();
> +  // Note: TypeOfExpr's aren't uniqued.
> +  return QualType(new TypeOfExpr(tofExpr, Canonical), 0);

In the comment, please explain why. :)

> +QualType ASTContext::getTypeOfType(QualType tofType) {
> +  QualType Canonical = tofType.getCanonicalType();
> +  // Note: TypeOfType's aren't uniqued.
> +  return QualType(new TypeOfType(tofType, Canonical), 0);

Unlike typeof(expr), I think that typeof(type) should be uniqued.  Do  
you agree?  If so, please add a FIXME (or implement it :).

> ====================================================================== 
> ========
> --- cfe/trunk/Parse/ParseDecl.cpp (original)
> +++ cfe/trunk/Parse/ParseDecl.cpp Tue Jul 31 07:34:36 2007
> @@ -482,6 +482,11 @@
>        ParseEnumSpecifier(DS);
>        continue;
>
> +    // GNU typeof support.
> +    case tok::kw_typeof:
> +      ParseTypeofSpecifier(DS);
> +      continue;

Cool, please remove the todo from the comment above the method:

/// [GNU]   typeof-specifier                      [TODO]


> @@ -1397,3 +1408,40 @@
>                                            NumElements.Val,  
> StartLoc));
>  }
>
> +/// [GNU] typeof-specifier:
> +///         typeof ( expressions )
> +///         typeof ( type-name )
> +///
> +void Parser::ParseTypeofSpecifier(DeclSpec &DS) {
> +  assert(Tok.getKind() == tok::kw_typeof && "Not a typeof  
> specifier");
> +  SourceLocation StartLoc = ConsumeToken();
> +
> +  if (Tok.getKind() != tok::l_paren) {
> +    // FIXME: handle error.
> +  }
> +  SourceLocation LParenLoc = ConsumeParen(), RParenLoc;
> +
> +  if (isTypeSpecifierQualifier()) {
> +    TypeTy *Ty = ParseTypeName();
> +
> +    const char *PrevSpec = 0;
> +    bool isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typeofType,  
> StartLoc,
> +                                        PrevSpec, Ty);
> +    // FIXME: what we have an invalid type? (or Ty is null)
> +  } else { // we have an expression.
> +    ExprResult Result = ParseExpression();
> +    if (Result.isInvalid) {
> +      SkipUntil(tok::r_paren);
> +    }
> +    const char *PrevSpec = 0;
> +    bool isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typeofExpr,  
> StartLoc,
> +                                        PrevSpec, Result.Val);
> +    // FIXME: what we have an invalid type? (or Result.Val is null)
> +  }

> +  // Match the ')'.
> +  if (Tok.getKind() == tok::r_paren)
> +    RParenLoc = ConsumeParen();
> +  else
> +    MatchRHSPunctuation(tok::r_paren, LParenLoc);

You can make this just be:

   // Match the ')'.
   MatchRHSPunctuation(tok::r_paren, LParenLoc);

Otherwise, very nice!

-Chris



More information about the cfe-commits mailing list