[cfe-commits] r69594 - in /cfe/trunk: include/clang/AST/DeclObjC.h include/clang/Frontend/PCHBitCodes.h lib/AST/DeclObjC.cpp lib/Frontend/PCHReader.cpp lib/Frontend/PCHWriter.cpp lib/Sema/SemaDeclObjC.cpp test/PCH/methods.h test/PCH/methods.m

Steve Naroff snaroff at apple.com
Mon Apr 20 08:06:19 PDT 2009


Author: snaroff
Date: Mon Apr 20 10:06:07 2009
New Revision: 69594

URL: http://llvm.org/viewvc/llvm-project?rev=69594&view=rev
Log:
Add pch reader/writer support for ObjCMethodDecl.

Test will be enabled with ObjCInterfaceDecl is added.

Added:
    cfe/trunk/test/PCH/methods.h
    cfe/trunk/test/PCH/methods.m
Modified:
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/include/clang/Frontend/PCHBitCodes.h
    cfe/trunk/lib/AST/DeclObjC.cpp
    cfe/trunk/lib/Frontend/PCHReader.cpp
    cfe/trunk/lib/Frontend/PCHWriter.cpp
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Mon Apr 20 10:06:07 2009
@@ -177,6 +177,7 @@
   // Location information, modeled after the Stmt API.
   SourceLocation getLocStart() const { return getLocation(); }
   SourceLocation getLocEnd() const { return EndLoc; }
+  void setEndLoc(SourceLocation Loc) { EndLoc = Loc; }
   SourceRange getSourceRange() const { 
     return SourceRange(getLocation(), EndLoc); 
   }
@@ -189,6 +190,7 @@
   Selector getSelector() const { return getDeclName().getObjCSelector(); }
   unsigned getSynthesizedMethodSize() const;
   QualType getResultType() const { return MethodDeclType; }
+  void setResultType(QualType T) { MethodDeclType = T; }
   
   // Iterator access to formal parameters.
   unsigned param_size() const { return ParamInfo.size(); }
@@ -196,8 +198,7 @@
   param_iterator param_begin() const { return ParamInfo.begin(); }
   param_iterator param_end() const { return ParamInfo.end(); }
 
-  void setMethodParams(ParmVarDecl *const *List, unsigned Num,
-                       ASTContext &C) {
+  void setMethodParams(ASTContext &C, ParmVarDecl *const *List, unsigned Num) {
     ParamInfo.set(List, Num, C);
   }
 
@@ -219,15 +220,19 @@
   void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID);
 
   ImplicitParamDecl * getSelfDecl() const { return SelfDecl; }
+  void setSelfDecl(ImplicitParamDecl *SD) { SelfDecl = SD; }
   ImplicitParamDecl * getCmdDecl() const { return CmdDecl; }
+  void setCmdDecl(ImplicitParamDecl *CD) { CmdDecl = CD; }
   
   bool isInstanceMethod() const { return IsInstance; }
+  void setInstanceMethod(bool isInst) { IsInstance = isInst; }
   bool isVariadic() const { return IsVariadic; }
+  void setVariadic(bool isVar) { IsVariadic = isVar; }
   
   bool isClassMethod() const { return !IsInstance; }
 
   bool isSynthesized() const { return IsSynthesized; }
-  void setIsSynthesized() { IsSynthesized = true; }
+  void setSynthesized(bool isSynth) { IsSynthesized = isSynth; }
   
   // Related to protocols declared in  @protocol
   void setDeclImplementation(ImplementationControl ic) { 

Modified: cfe/trunk/include/clang/Frontend/PCHBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHBitCodes.h?rev=69594&r1=69593&r2=69594&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHBitCodes.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHBitCodes.h Mon Apr 20 10:06:07 2009
@@ -354,6 +354,8 @@
       DECL_ENUM_CONSTANT,
       /// \brief A FunctionDecl record.
       DECL_FUNCTION,
+      /// \brief A ObjCMethodDecl record.
+      DECL_OBJC_METHOD,
       /// \brief A FieldDecl record.
       DECL_FIELD,
       /// \brief A VarDecl record.

Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=69594&r1=69593&r2=69594&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Mon Apr 20 10:06:07 2009
@@ -285,12 +285,12 @@
   } else // we have a factory method.
     selfTy = Context.getObjCClassType();
 
-  SelfDecl = ImplicitParamDecl::Create(Context, this, SourceLocation(), 
-                                       &Context.Idents.get("self"), selfTy);
+  setSelfDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(), 
+                                        &Context.Idents.get("self"), selfTy));
 
-  CmdDecl = ImplicitParamDecl::Create(Context, this, SourceLocation(), 
-                                      &Context.Idents.get("_cmd"), 
-                                      Context.getObjCSelType());
+  setCmdDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(), 
+                                       &Context.Idents.get("_cmd"), 
+                                       Context.getObjCSelType()));
 }
 
 

Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=69594&r1=69593&r2=69594&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Mon Apr 20 10:06:07 2009
@@ -67,6 +67,7 @@
     void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
     void VisitBlockDecl(BlockDecl *BD);
     std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
+    void VisitObjCMethodDecl(ObjCMethodDecl *D);
   };
 }
 
@@ -159,6 +160,30 @@
   FD->setParams(Reader.getContext(), &Params[0], NumParams);
 }
 
+void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
+  VisitNamedDecl(MD);
+  if (Record[Idx++]) {
+    // In practice, this won't be executed (since method definitions
+    // don't occur in header files).
+    MD->setBody(cast<CompoundStmt>(Reader.GetStmt(Record[Idx++])));
+    MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
+    MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
+  }
+  MD->setInstanceMethod(Record[Idx++]);
+  MD->setVariadic(Record[Idx++]);
+  MD->setSynthesized(Record[Idx++]);
+  MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
+  MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
+  MD->setResultType(Reader.GetType(Record[Idx++]));
+  MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  unsigned NumParams = Record[Idx++];
+  llvm::SmallVector<ParmVarDecl *, 16> Params;
+  Params.reserve(NumParams);
+  for (unsigned I = 0; I != NumParams; ++I)
+    Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
+  MD->setMethodParams(Reader.getContext(), &Params[0], NumParams);
+}
+
 void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
   VisitValueDecl(FD);
   FD->setMutable(Record[Idx++]);
@@ -1770,6 +1795,12 @@
     break;
   }
 
+  case pch::DECL_OBJC_METHOD: {
+    D = ObjCMethodDecl::Create(Context, SourceLocation(), SourceLocation(), 
+                               Selector(), QualType(), 0);
+    break;
+  }
+
   case pch::DECL_FIELD: {
     D = FieldDecl::Create(Context, 0, SourceLocation(), 0, QualType(), 0, 
                           false);

Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=69594&r1=69593&r2=69594&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Mon Apr 20 10:06:07 2009
@@ -270,6 +270,7 @@
     void VisitBlockDecl(BlockDecl *D);
     void VisitDeclContext(DeclContext *DC, uint64_t LexicalOffset, 
                           uint64_t VisibleOffset);
+    void VisitObjCMethodDecl(ObjCMethodDecl *D);
   };
 }
 
@@ -359,6 +360,32 @@
   Code = pch::DECL_FUNCTION;
 }
 
+void PCHDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) {
+  VisitNamedDecl(D);
+  // FIXME: convert to LazyStmtPtr?
+  // Unlike C/C++, method bodies will never be in header files. 
+  Record.push_back(D->getBody() != 0);
+  if (D->getBody() != 0) {
+    Writer.AddStmt(D->getBody(Context));
+    Writer.AddDeclRef(D->getSelfDecl(), Record);
+    Writer.AddDeclRef(D->getCmdDecl(), Record);
+  }
+  Record.push_back(D->isInstanceMethod());
+  Record.push_back(D->isVariadic());
+  Record.push_back(D->isSynthesized());
+  // FIXME: stable encoding for @required/@optional
+  Record.push_back(D->getImplementationControl()); 
+  // FIXME: stable encoding for in/out/inout/bycopy/byref/oneway
+  Record.push_back(D->getObjCDeclQualifier()); 
+  Writer.AddTypeRef(D->getResultType(), Record);
+  Writer.AddSourceLocation(D->getLocEnd(), Record);
+  Record.push_back(D->param_size());
+  for (ObjCMethodDecl::param_iterator P = D->param_begin(), 
+                                   PEnd = D->param_end(); P != PEnd; ++P)
+    Writer.AddDeclRef(*P, Record);
+  Code = pch::DECL_OBJC_METHOD;
+}
+
 void PCHDeclWriter::VisitFieldDecl(FieldDecl *D) {
   VisitValueDecl(D);
   Record.push_back(D->isMutable());

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=69594&r1=69593&r2=69594&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Mon Apr 20 10:06:07 2009
@@ -1226,7 +1226,7 @@
   } else
     // A user declared getter will be synthesize when @synthesize of
     // the property with the same name is seen in the @implementation
-    GetterMethod->setIsSynthesized();
+    GetterMethod->setSynthesized(true);
   property->setGetterMethodDecl(GetterMethod);
 
   // Skip setter if property is read-only.
@@ -1252,12 +1252,12 @@
                                                   property->getType(),
                                                   VarDecl::None,
                                                   0);
-      SetterMethod->setMethodParams(&Argument, 1, Context);
+      SetterMethod->setMethodParams(Context, &Argument, 1);
       CD->addDecl(Context, SetterMethod);
     } else
       // A user declared setter will be synthesize when @synthesize of
       // the property with the same name is seen in the @implementation
-      SetterMethod->setIsSynthesized();
+      SetterMethod->setSynthesized(true);
     property->setSetterMethodDecl(SetterMethod);
   }
   // Add any synthesized methods to the global pool. This allows us to 
@@ -1506,7 +1506,7 @@
     Params.push_back(Param);
   }
 
-  ObjCMethod->setMethodParams(&Params[0], Sel.getNumArgs(), Context);
+  ObjCMethod->setMethodParams(Context, &Params[0], Sel.getNumArgs());
   ObjCMethod->setObjCDeclQualifier(
     CvtQTToAstBitMask(ReturnQT.getObjCDeclQualifier()));
   const ObjCMethodDecl *PrevMethod = 0;

Added: cfe/trunk/test/PCH/methods.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/methods.h?rev=69594&view=auto

==============================================================================
--- cfe/trunk/test/PCH/methods.h (added)
+++ cfe/trunk/test/PCH/methods.h Mon Apr 20 10:06:07 2009
@@ -0,0 +1,6 @@
+/* For use with the methods.m test */
+
+ at interface TestPCH
++ alloc;
+- (void)instMethod;
+ at end

Added: cfe/trunk/test/PCH/methods.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/methods.m?rev=69594&view=auto

==============================================================================
--- cfe/trunk/test/PCH/methods.m (added)
+++ cfe/trunk/test/PCH/methods.m Mon Apr 20 10:06:07 2009
@@ -0,0 +1,11 @@
+// Test this without pch.
+// FIXME: clang-cc -include %S/methods.h -fsyntax-only -verify %s &&
+
+// Test with pch.
+// FIXME: clang-cc -x=objective-c -emit-pch -o %t %S/methods.h &&
+// FIXME: clang-cc -include-pch %t -fsyntax-only -verify %s 
+
+void func() {
+ TestPCH *xx = [TestPCH alloc];
+ [xx instMethod];
+}





More information about the cfe-commits mailing list