]> granicus.if.org Git - clang/commitdiff
Two typeof() related changes...
authorSteve Naroff <snaroff@apple.com>
Wed, 1 Aug 2007 17:20:42 +0000 (17:20 +0000)
committerSteve Naroff <snaroff@apple.com>
Wed, 1 Aug 2007 17:20:42 +0000 (17:20 +0000)
- 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40676 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 6f7165101e9ccef655eb4f6e3fe5feee2c455dd5..12de403e3ce1383d1674f1f017623906d7d78e4e 100644 (file)
@@ -584,7 +584,7 @@ QualType ASTContext::getTypedefType(TypedefDecl *Decl) {
   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);
index 15f0968b81cc9d04b43f59f509b1273595494a9c..63a681a52c32eabb1c894625d5383613ea9a1eb7 100644 (file)
@@ -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 OCUVectorType::getAsStringInternal(std::string &S) const {
 }
 
 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 {
index a1dd1f7cda5018b2305cde820ce0b07d3ee0ae22..a1e9e1ccc27ef5e784f36cb582a1200c0efa984d 100644 (file)
@@ -105,7 +105,7 @@ static QualType ConvertDeclSpecToType(const DeclSpec &DS, ASTContext &Ctx) {
     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);
   }
   }
 }
index 5d4c11b9cda2b04fe9c158775631d226e007f75b..240f54689d574f5e5a390e52d974320cf13f9f8f 100644 (file)
@@ -101,7 +101,7 @@ public:
   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
index f700fa24bf44cdc1d57ae9e261fbe48a4e66b453..acf82964145d8ba7fedddaa0294716da38bac47f 100644 (file)
@@ -604,21 +604,21 @@ DIAG(err_typecheck_indirection_requires_pointer, ERROR,
      "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 @@ DIAG(err_typecheck_call_too_many_args, ERROR,
      "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 @@ DIAG(err_typecheck_expect_scalar_operand, ERROR,
      "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 @@ DIAG(err_case_not_in_switch, ERROR,
      "'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)")
index 8556687123c52f5e48606ff5c38810d7e4231b06..14025e58095f505287ad259c2c63ea26eaab9deb 100644 (file)
@@ -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 *'}}
 }