[cfe-commits] r41555 - in /cfe/trunk: Sema/SemaDecl.cpp Sema/SemaExpr.cpp Sema/SemaType.cpp include/clang/AST/Decl.h

Steve Naroff snaroff at apple.com
Tue Aug 28 13:14:25 PDT 2007


Author: snaroff
Date: Tue Aug 28 15:14:24 2007
New Revision: 41555

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

Finish converting decls over to the new invalid decl API.

Also removed an old FIXME (FIXME: "auto func();" passes through...).

Modified:
    cfe/trunk/Sema/SemaDecl.cpp
    cfe/trunk/Sema/SemaExpr.cpp
    cfe/trunk/Sema/SemaType.cpp
    cfe/trunk/include/clang/AST/Decl.h

Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=41555&r1=41554&r2=41555&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Tue Aug 28 15:14:24 2007
@@ -304,6 +304,8 @@
     PrevDecl = 0;   // If in outer scope, it isn't the same thing.
 
   Decl *New;
+  bool InvalidDecl = false;
+  
   if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef) {
     assert(Init == 0 && "Can't have initializer for a typedef!");
     TypedefDecl *NewTD = ParseTypedefDecl(S, D, LastDeclarator);
@@ -323,13 +325,14 @@
       // then it shall have block scope.
       if (ArrayType *ary = dyn_cast<ArrayType>(NewTD->getUnderlyingType())) {
         if (VerifyConstantArrayType(ary, D.getIdentifierLoc()))
-          return 0;
+          InvalidDecl = true;
       }
     }
   } else if (D.isFunctionDeclarator()) {
     assert(Init == 0 && "Can't have an initializer for a functiondecl!");
+    
     QualType R = GetTypeForDeclarator(D, S);
-    if (R.isNull()) return 0; // FIXME: "auto func();" passes through...
+    assert(!R.isNull() && "GetTypeForDeclarator() returned null type");
 
     FunctionDecl::StorageClass SC;
     switch (D.getDeclSpec().getStorageClassSpec()) {
@@ -338,7 +341,8 @@
       case DeclSpec::SCS_register:
         Diag(D.getIdentifierLoc(), diag::err_typecheck_sclass_func,
              R.getAsString());
-        return 0;
+        InvalidDecl = true;
+        break;
       case DeclSpec::SCS_unspecified: SC = FunctionDecl::None; break;
       case DeclSpec::SCS_extern:      SC = FunctionDecl::Extern; break;
       case DeclSpec::SCS_static:      SC = FunctionDecl::Static; break;
@@ -356,9 +360,7 @@
     New = NewFD;
   } else {
     QualType R = GetTypeForDeclarator(D, S);
-    
     assert(!R.isNull() && "GetTypeForDeclarator() returned null type");
-    bool InvalidDecl = false;
 
     VarDecl *NewVD;
     VarDecl::StorageClass SC;
@@ -420,9 +422,6 @@
       }
       NewVD = new BlockVarDecl(D.getIdentifierLoc(), II, R, SC, LastDeclarator);
     }
-    if (InvalidDecl)
-      NewVD->setInvalidDecl();
-      
     // Handle attributes prior to checking for duplicates in MergeVarDecl
     HandleDeclAttributes(NewVD, D.getDeclSpec().getAttributes(),
                          D.getAttributes());
@@ -450,6 +449,10 @@
   
   if (S->getParent() == 0)
     AddTopLevelDecl(New, LastDeclarator);
+
+  // If any semantic error occurred, mark the decl as invalid.
+  if (D.getInvalidType() || InvalidDecl)
+    New->setInvalidDecl();
   
   return New;
 }
@@ -649,11 +652,14 @@
   assert(D.getIdentifier() && "Wrong callback for declspec without declarator");
   
   QualType T = GetTypeForDeclarator(D, S);
-  if (T.isNull()) return 0;
+  assert(!T.isNull() && "GetTypeForDeclarator() returned null type");
   
   // Scope manipulation handled by caller.
-  return new TypedefDecl(D.getIdentifierLoc(), D.getIdentifier(), T,
-                         LastDeclarator);
+  TypedefDecl *NewTD = new TypedefDecl(D.getIdentifierLoc(), D.getIdentifier(), 
+                                       T, LastDeclarator);
+  if (D.getInvalidType())
+    NewTD->setInvalidDecl();
+  return NewTD;
 }
 
 
@@ -789,17 +795,21 @@
   }
   
   QualType T = GetTypeForDeclarator(D, S);
-  if (T.isNull()) return 0;
+  assert(!T.isNull() && "GetTypeForDeclarator() returned null type");
+  bool InvalidDecl = false;
   
   // C99 6.7.2.1p8: A member of a structure or union may have any type other
   // than a variably modified type.
   if (const ArrayType *ary = T->getAsArrayType()) {
     if (VerifyConstantArrayType(ary, Loc))
-      return 0;
+      InvalidDecl = true;
   }
   
   // FIXME: Chain fielddecls together.
-  return new FieldDecl(Loc, II, T, 0);
+  FieldDecl *NewFD = new FieldDecl(Loc, II, T, 0);
+  if (D.getInvalidType() || InvalidDecl)
+    NewFD->setInvalidDecl();
+  return NewFD;
 }
 
 void Sema::ParseRecordBody(SourceLocation RecLoc, DeclTy *RecDecl,

Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=41555&r1=41554&r2=41555&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Tue Aug 28 15:14:24 2007
@@ -76,7 +76,7 @@
   }
   if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
     // Only create DeclRefExpr's for valid Decl's.
-    if (VD->getInvalidDecl())
+    if (VD->isInvalidDecl())
       return true;
     return new DeclRefExpr(VD, VD->getType(), Loc);
   }

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

==============================================================================
--- cfe/trunk/Sema/SemaType.cpp (original)
+++ cfe/trunk/Sema/SemaType.cpp Tue Aug 28 15:14:24 2007
@@ -278,11 +278,12 @@
   assert(D.getIdentifier() == 0 && "Type name should have no identifier!");
   
   QualType T = GetTypeForDeclarator(D, S);
+
+  assert(!T.isNull() && "GetTypeForDeclarator() returned null type");
   
-  // If the type of the declarator was invalid, this is an invalid typename.
-  if (T.isNull())
-    return true;
-  
+  // In this context, we *do not* check D.getInvalidType(). If the declarator
+  // type was invalid, GetTypeForDeclarator() still returns a "valid" type,
+  // though it will not reflect the user specified type.
   return T.getAsOpaquePtr();
 }
 
@@ -292,9 +293,10 @@
   // just want the type converted.
   QualType T = GetTypeForDeclarator(D, S);
   
-  // If the type of the declarator was invalid, this is an invalid typename.
-  if (T.isNull())
-    return true;
-  
+  assert(!T.isNull() && "GetTypeForDeclarator() returned null type");
+
+  // In this context, we *do not* check D.getInvalidType(). If the declarator
+  // type was invalid, GetTypeForDeclarator() still returns a "valid" type,
+  // though it will not reflect the user specified type.
   return T.getAsOpaquePtr();
 }

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

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Tue Aug 28 15:14:24 2007
@@ -92,7 +92,7 @@
   /// setInvalidDecl - Indicates the Decl had a semantic error. This
   /// allows for graceful error recovery.
   void setInvalidDecl() { InvalidDecl = 1; }
-  int getInvalidDecl() const { return InvalidDecl; }
+  int isInvalidDecl() const { return InvalidDecl; }
   
   /// getNextDeclarator - If this decl was part of a multi-declarator
   /// declaration, such as "int X, Y, *Z;" this returns the decl for the next





More information about the cfe-commits mailing list