[cfe-commits] r98362 - in /cfe/trunk: include/clang/AST/Decl.h lib/AST/ASTImporter.cpp lib/Frontend/PCHReaderDecl.cpp lib/Frontend/PCHWriterDecl.cpp lib/Sema/SemaDeclCXX.cpp

John McCall rjmccall at apple.com
Fri Mar 12 10:31:32 PST 2010


Author: rjmccall
Date: Fri Mar 12 12:31:32 2010
New Revision: 98362

URL: http://llvm.org/viewvc/llvm-project?rev=98362&view=rev
Log:
Remember whether a ParmVarDecl was spelled with a default argument or
whether it inherited one from a previous declaration.

Patch by Enea Zaffanella!


Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/lib/AST/ASTImporter.cpp
    cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
    cfe/trunk/lib/Frontend/PCHWriterDecl.cpp
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=98362&r1=98361&r2=98362&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Fri Mar 12 12:31:32 2010
@@ -809,12 +809,14 @@
   /// FIXME: Also can be paced into the bitfields in Decl.
   /// in, inout, etc.
   unsigned objcDeclQualifier : 6;
+  bool HasInheritedDefaultArg : 1;
 
 protected:
   ParmVarDecl(Kind DK, DeclContext *DC, SourceLocation L,
               IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo,
               StorageClass S, Expr *DefArg)
-  : VarDecl(DK, DC, L, Id, T, TInfo, S), objcDeclQualifier(OBJC_TQ_None) {
+  : VarDecl(DK, DC, L, Id, T, TInfo, S),
+    objcDeclQualifier(OBJC_TQ_None), HasInheritedDefaultArg(false) {
     setDefaultArg(DefArg);
   }
 
@@ -893,6 +895,14 @@
     Init = (UnparsedDefaultArgument *)0;
   }
 
+  bool hasInheritedDefaultArg() const {
+    return HasInheritedDefaultArg;
+  }
+
+  void setHasInheritedDefaultArg(bool I = true) {
+    HasInheritedDefaultArg = I;
+  }
+
   QualType getOriginalType() const {
     if (getTypeSourceInfo())
       return getTypeSourceInfo()->getType();

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=98362&r1=98361&r2=98362&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Fri Mar 12 12:31:32 2010
@@ -2176,6 +2176,7 @@
                                             Loc, Name.getAsIdentifierInfo(),
                                             T, TInfo, D->getStorageClass(),
                                             /*FIXME: Default argument*/ 0);
+  ToParm->setHasInheritedDefaultArg(D->hasInheritedDefaultArg());
   return Importer.Imported(D, ToParm);
 }
 

Modified: cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderDecl.cpp?rev=98362&r1=98361&r2=98362&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderDecl.cpp Fri Mar 12 12:31:32 2010
@@ -411,6 +411,7 @@
 void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
   VisitVarDecl(PD);
   PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
+  PD->setHasInheritedDefaultArg(Record[Idx++]);
 }
 
 void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {

Modified: cfe/trunk/lib/Frontend/PCHWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriterDecl.cpp?rev=98362&r1=98361&r2=98362&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriterDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriterDecl.cpp Fri Mar 12 12:31:32 2010
@@ -398,6 +398,7 @@
 void PCHDeclWriter::VisitParmVarDecl(ParmVarDecl *D) {
   VisitVarDecl(D);
   Record.push_back(D->getObjCDeclQualifier()); // FIXME: stable encoding
+  Record.push_back(D->hasInheritedDefaultArg());
   Code = pch::DECL_PARM_VAR;
 
 
@@ -412,7 +413,8 @@
       D->getPCHLevel() == 0 &&
       D->getStorageClass() == 0 &&
       !D->hasCXXDirectInitializer() && // Can params have this ever?
-      D->getObjCDeclQualifier() == 0)
+      D->getObjCDeclQualifier() == 0 &&
+      !D->hasInheritedDefaultArg())
     AbbrevToUse = Writer.getParmVarDeclAbbrev();
 
   // Check things we know are true of *every* PARM_VAR_DECL, which is more than
@@ -496,6 +498,7 @@
   Abv->Add(BitCodeAbbrevOp(0));                       // HasInit
   // ParmVarDecl
   Abv->Add(BitCodeAbbrevOp(0));                       // ObjCDeclQualifier
+  Abv->Add(BitCodeAbbrevOp(0));                       // HasInheritedDefaultArg
 
   ParmVarDeclAbbrev = Stream.EmitAbbrev(Abv);
 }

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=98362&r1=98361&r2=98362&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Mar 12 12:31:32 2010
@@ -298,6 +298,7 @@
       Invalid = true;
     } else if (OldParam->hasDefaultArg()) {
       // Merge the old default argument into the new parameter
+      NewParam->setHasInheritedDefaultArg();
       if (OldParam->hasUninstantiatedDefaultArg())
         NewParam->setUninstantiatedDefaultArg(
                                       OldParam->getUninstantiatedDefaultArg());





More information about the cfe-commits mailing list