[cfe-commits] r40676 - in /cfe/trunk: AST/ASTContext.cpp AST/Type.cpp Sema/SemaType.cpp include/clang/AST/ASTContext.h include/clang/Basic/DiagnosticKinds.def test/Parser/typeof.c

Steve Naroff snaroff at apple.com
Wed Aug 1 10:20:43 PDT 2007


Author: snaroff
Date: Wed Aug  1 12:20:42 2007
New Revision: 40676

URL: http://llvm.org/viewvc/llvm-project?rev=40676&view=rev
Log:

Two typeof() related changes...

- Changed the name of ASTContext::getTypeOfType(Expr*)->getTypeOfExpr().
- Remove FIXME for TypeOfExpr::getAsStringInternal(). This will work fine for printing the AST. It isn't ideal
for error diagnostics (since it's more natural to display the expressions type). 

One "random" (or at least delayed:-) change...

- Changed all "ext_typecheck_*" diagnostics from EXTENSION->WARNING. Reason: Since -pedantic is now
off (by default), these diagnostics were never being emitted (which is bad). With this change, clang will
emit the warning all the time. The only downside (wrt GCC compatibility) is -pedantic-errors will not turn
this diagnostics into errors (a "feature" of making tagging them with EXTENSION). When/if this becomes
an issue, we can revisit.


Modified:
    cfe/trunk/AST/ASTContext.cpp
    cfe/trunk/AST/Type.cpp
    cfe/trunk/Sema/SemaType.cpp
    cfe/trunk/include/clang/AST/ASTContext.h
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def
    cfe/trunk/test/Parser/typeof.c

Modified: cfe/trunk/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/ASTContext.cpp?rev=40676&r1=40675&r2=40676&view=diff

==============================================================================
--- cfe/trunk/AST/ASTContext.cpp (original)
+++ cfe/trunk/AST/ASTContext.cpp Wed Aug  1 12:20:42 2007
@@ -584,7 +584,7 @@
   return QualType(Decl->TypeForDecl, 0);
 }
 
-QualType ASTContext::getTypeOfType(Expr *tofExpr) {
+QualType ASTContext::getTypeOfExpr(Expr *tofExpr) {
   QualType Canonical = tofExpr->getType().getCanonicalType();
   // Note: TypeOfExpr's aren't uniqued.
   return QualType(new TypeOfExpr(tofExpr, Canonical), 0);

Modified: cfe/trunk/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Type.cpp?rev=40676&r1=40675&r2=40676&view=diff

==============================================================================
--- cfe/trunk/AST/Type.cpp (original)
+++ cfe/trunk/AST/Type.cpp Wed Aug  1 12:20:42 2007
@@ -18,6 +18,8 @@
 #include "clang/Basic/TargetInfo.h"
 #include "llvm/Support/Streams.h"
 #include "llvm/ADT/StringExtras.h"
+#include <sstream>
+
 using namespace clang;
 
 Type::~Type() {}
@@ -652,9 +654,9 @@
 }
 
 void TypeOfExpr::getAsStringInternal(std::string &InnerString) const {
-  // FIXME: output expression, getUnderlyingExpr()->print().
-  // At the moment, Stmt::print(std::ostream) doesn't work for us here.
-  InnerString = "typeof(<expr>) " + InnerString;
+  std::ostringstream s;
+  getUnderlyingExpr()->print(s);
+  InnerString = "typeof(" + s.str() + ") " + InnerString;
 }
 
 void TypeOfType::getAsStringInternal(std::string &S) const {

Modified: cfe/trunk/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaType.cpp?rev=40676&r1=40675&r2=40676&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaType.cpp (original)
+++ cfe/trunk/Sema/SemaType.cpp Wed Aug  1 12:20:42 2007
@@ -105,7 +105,7 @@
     Expr *E = static_cast<Expr *>(DS.getTypeRep());
     assert(E && "Didn't get an expression for typeof?");
     // TypeQuals handled by caller.
-    return Ctx.getTypeOfType(E);
+    return Ctx.getTypeOfExpr(E);
   }
   }
 }

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=40676&r1=40675&r2=40676&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Wed Aug  1 12:20:42 2007
@@ -101,7 +101,7 @@
   QualType getTypedefType(TypedefDecl *Decl);
 
   /// getTypeOfType - GCC extension.
-  QualType getTypeOfType(Expr *e);
+  QualType getTypeOfExpr(Expr *e);
   QualType getTypeOfType(QualType t);
   
   /// getTagDeclType - Return the unique reference to the type for the

Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=40676&r1=40675&r2=40676&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Aug  1 12:20:42 2007
@@ -604,21 +604,21 @@
      "indirection requires pointer operand ('%0' invalid)")
 DIAG(err_typecheck_deref_incomplete_type, ERROR,
      "dereferencing pointer to incomplete type '%0'")
-DIAG(ext_typecheck_deref_ptr_to_void, EXTENSION,
+DIAG(ext_typecheck_deref_ptr_to_void, WARNING,
      "dereferencing '%0' pointer")
 DIAG(err_typecheck_invalid_operands, ERROR,
      "invalid operands to binary expression ('%0' and '%1')")
-DIAG(ext_typecheck_comparison_of_pointer_integer, EXTENSION,
+DIAG(ext_typecheck_comparison_of_pointer_integer, WARNING,
      "comparison between pointer and integer")
 DIAG(err_typecheck_assign_const, ERROR,
      "read-only variable is not assignable")
 DIAG(err_typecheck_assign_incompatible, ERROR,
      "incompatible types assigning '%1' to '%0'")
-DIAG(ext_typecheck_assign_pointer_int, EXTENSION,
+DIAG(ext_typecheck_assign_pointer_int, WARNING,
      "incompatible types assigning '%1' to '%0'")
-DIAG(ext_typecheck_assign_incompatible_pointer, EXTENSION,
+DIAG(ext_typecheck_assign_incompatible_pointer, WARNING,
      "incompatible pointer types assigning '%1' to '%0'")
-DIAG(ext_typecheck_assign_discards_qualifiers, EXTENSION,
+DIAG(ext_typecheck_assign_discards_qualifiers, WARNING,
      "assigning '%1' to '%0' discards qualifiers")
 DIAG(err_typecheck_array_not_modifiable_lvalue, ERROR,
      "array type '%0' is not assignable")
@@ -638,11 +638,11 @@
      "too many arguments to function")
 DIAG(err_typecheck_passing_incompatible, ERROR,
      "incompatible types passing '%0' to function expecting '%1'")
-DIAG(ext_typecheck_passing_incompatible_pointer, EXTENSION,
+DIAG(ext_typecheck_passing_incompatible_pointer, WARNING,
      "incompatible pointer types passing '%0' to function expecting '%1'")
-DIAG(ext_typecheck_passing_pointer_int, EXTENSION,
+DIAG(ext_typecheck_passing_pointer_int, WARNING,
      "incompatible types passing '%1' to function expecting '%0'")
-DIAG(ext_typecheck_passing_discards_qualifiers, EXTENSION,
+DIAG(ext_typecheck_passing_discards_qualifiers, WARNING,
      "passing '%0' to '%1' discards qualifiers")
 DIAG(err_typecheck_cond_expect_scalar, ERROR,
      "used type '%0' where arithmetic or pointer type is required")
@@ -650,7 +650,7 @@
      "operand of type '%0' where arithmetic or pointer type is required")
 DIAG(err_typecheck_cond_incompatible_operands, ERROR,
      "incompatible operand types ('%0' and '%1')")
-DIAG(ext_typecheck_cond_incompatible_pointers, EXTENSION,
+DIAG(ext_typecheck_cond_incompatible_pointers, WARNING,
      "pointer type mismatch ('%0' and '%1')")
 
 DIAG(warn_unused_expr, WARNING,
@@ -667,11 +667,11 @@
      "'case' statement not in switch statement")
 DIAG(err_typecheck_return_incompatible, ERROR,
      "incompatible type returning '%1', expected '%0'")
-DIAG(ext_typecheck_return_pointer_int, EXTENSION,
+DIAG(ext_typecheck_return_pointer_int, WARNING,
      "incompatible type returning '%1', expected '%0'")
-DIAG(ext_typecheck_return_incompatible_pointer, EXTENSION,
+DIAG(ext_typecheck_return_incompatible_pointer, WARNING,
      "incompatible pointer type returning '%1', expected '%0'")
-DIAG(ext_typecheck_return_discards_qualifiers, EXTENSION,
+DIAG(ext_typecheck_return_discards_qualifiers, WARNING,
      "returning '%1' from function expecting '%0' discards qualifiers")
 DIAG(err_typecheck_statement_requires_scalar, ERROR,
      "statement requires expression of scalar type ('%0' invalid)")

Modified: cfe/trunk/test/Parser/typeof.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/typeof.c?rev=40676&r1=40675&r2=40676&view=diff

==============================================================================
--- cfe/trunk/test/Parser/typeof.c (original)
+++ cfe/trunk/test/Parser/typeof.c Wed Aug  1 12:20:42 2007
@@ -1,23 +1,23 @@
-// RUN: clang -parse-ast-check %s -pedantic
+// RUN: clang -parse-ast-check %s
 
 typedef int TInt;
 
 static void test() {
   int *pi;
 
-  int typeof (int) aIntInt; // expected-error{{cannot combine with previous 'int' declaration specifier}} expected-warning{{extension used}}
-  short typeof (int) aShortInt; // expected-error{{'short typeof' is invalid}} expected-warning{{extension used}}
+  int typeof (int) aIntInt; // expected-error{{cannot combine with previous 'int' declaration specifier}}
+  short typeof (int) aShortInt; // expected-error{{'short typeof' is invalid}} 
   int int ttt; // expected-error{{cannot combine with previous 'int' declaration specifier}}
-  typeof(TInt) anInt; // expected-warning{{extension used}}
+  typeof(TInt) anInt; 
   short TInt eee; // expected-error{{parse error}}
   void ary[7] fff; // expected-error{{array has incomplete element type 'void'}} expected-error{{parse error}}
-  typeof(void ary[7]) anIntError; // expected-warning{{extension used}} expected-error{{expected ')'}} expected-error{{to match this '('}}
-  typeof(const int) aci; // expected-warning{{extension used}}
-  const typeof (*pi) aConstInt; // expected-warning{{extension used}}
+  typeof(void ary[7]) anIntError; // expected-error{{expected ')'}} expected-error{{to match this '('}}
+  typeof(const int) aci; 
+  const typeof (*pi) aConstInt; 
   int xx;
   int *i;
   i = aci; // expected-warning{{incompatible types assigning 'typeof(int const)' to 'int *'}}
   i = anInt; // expected-warning{{incompatible types assigning 'typeof(TInt)' to 'int *'}}
-  i = aConstInt; // expected-warning{{incompatible types assigning 'typeof(<expr>) const' to 'int *'}}
+  i = aConstInt; // expected-warning{{incompatible types assigning 'typeof(*pi) const' to 'int *'}}
   i = xx; // expected-warning{{incompatible types assigning 'int' to 'int *'}}
 }





More information about the cfe-commits mailing list