]> granicus.if.org Git - clang/commitdiff
Implement method type encoding in the presense
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 8 Apr 2010 21:29:11 +0000 (21:29 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 8 Apr 2010 21:29:11 +0000 (21:29 +0000)
of c-style arguments. Completes radar 7445205.

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

include/clang/AST/DeclObjC.h
lib/AST/ASTContext.cpp
lib/AST/DeclObjC.cpp
lib/Frontend/PCHReaderDecl.cpp
lib/Frontend/PCHWriterDecl.cpp
lib/Sema/SemaDeclObjC.cpp
test/CodeGenObjC/encode-cstyle-method.m [new file with mode: 0644]

index 9b2b6096e81d902ac5945625f6f1b621c9983177..388e9acb9196b74d20cf6c4d35497ed0a52d6a74 100644 (file)
@@ -136,6 +136,9 @@ private:
   /// in, inout, etc.
   unsigned objcDeclQualifier : 6;
 
+  // Number of args separated by ':' in a method declaration.
+  unsigned NumSelectorArgs;
+
   // Result type of this method.
   QualType MethodDeclType;
   
@@ -167,13 +170,15 @@ private:
                  bool isInstance = true,
                  bool isVariadic = false,
                  bool isSynthesized = false,
-                 ImplementationControl impControl = None)
+                 ImplementationControl impControl = None,
+                 unsigned numSelectorArgs = 0)
   : NamedDecl(ObjCMethod, contextDecl, beginLoc, SelInfo),
     DeclContext(ObjCMethod),
     IsInstance(isInstance), IsVariadic(isVariadic),
     IsSynthesized(isSynthesized),
     DeclImplementation(impControl), objcDeclQualifier(OBJC_TQ_None),
-    MethodDeclType(T), ResultTInfo(ResultTInfo),
+    NumSelectorArgs(numSelectorArgs), MethodDeclType(T), 
+    ResultTInfo(ResultTInfo),
     EndLoc(endLoc), Body(0), SelfDecl(0), CmdDecl(0) {}
 
   virtual ~ObjCMethodDecl() {}
@@ -197,7 +202,8 @@ public:
                                 bool isInstance = true,
                                 bool isVariadic = false,
                                 bool isSynthesized = false,
-                                ImplementationControl impControl = None);
+                                ImplementationControl impControl = None,
+                                unsigned numSelectorArgs = 0);
 
   virtual ObjCMethodDecl *getCanonicalDecl();
   const ObjCMethodDecl *getCanonicalDecl() const {
@@ -209,6 +215,11 @@ public:
   }
   void setObjCDeclQualifier(ObjCDeclQualifier QV) { objcDeclQualifier = QV; }
 
+  unsigned getNumSelectorArgs() const { return NumSelectorArgs; }
+  void setNumSelectorArgs(unsigned numSelectorArgs) { 
+    NumSelectorArgs = numSelectorArgs; 
+  }
+  
   // Location information, modeled after the Stmt API.
   SourceLocation getLocStart() const { return getLocation(); }
   SourceLocation getLocEnd() const { return EndLoc; }
@@ -235,6 +246,11 @@ public:
   typedef ObjCList<ParmVarDecl>::iterator param_iterator;
   param_iterator param_begin() const { return ParamInfo.begin(); }
   param_iterator param_end() const { return ParamInfo.end(); }
+  // This method returns and of the parameters which are part of the selector
+  // name mangling requirements.
+  param_iterator sel_param_end() const { 
+    return ParamInfo.begin() + NumSelectorArgs; 
+  }
 
   void setMethodParams(ASTContext &C, ParmVarDecl *const *List, unsigned Num) {
     ParamInfo.set(List, Num, C);
index 513bbd387145b274fbf8d8d87daaf439be68054d..1fa17f0b4b98a116b3a0913b076bcdba96e97e0b 100644 (file)
@@ -3258,7 +3258,7 @@ void ASTContext::getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl,
   // their size.
   CharUnits ParmOffset = 2 * PtrSize;
   for (ObjCMethodDecl::param_iterator PI = Decl->param_begin(),
-       E = Decl->param_end(); PI != E; ++PI) {
+       E = Decl->sel_param_end(); PI != E; ++PI) {
     QualType PType = (*PI)->getType();
     CharUnits sz = getObjCEncodingTypeSize(PType);
     assert (sz.isPositive() && 
@@ -3272,7 +3272,7 @@ void ASTContext::getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl,
   // Argument types.
   ParmOffset = 2 * PtrSize;
   for (ObjCMethodDecl::param_iterator PI = Decl->param_begin(),
-       E = Decl->param_end(); PI != E; ++PI) {
+       E = Decl->sel_param_end(); PI != E; ++PI) {
     ParmVarDecl *PVDecl = *PI;
     QualType PType = PVDecl->getOriginalType();
     if (const ArrayType *AT =
index 821e38bdacfd0cc484ec9c45a570bdc3705981e2..db46d89a762b1657be8b51d0c84b7133a7a02625 100644 (file)
@@ -330,11 +330,13 @@ ObjCMethodDecl *ObjCMethodDecl::Create(ASTContext &C,
                                        bool isInstance,
                                        bool isVariadic,
                                        bool isSynthesized,
-                                       ImplementationControl impControl) {
+                                       ImplementationControl impControl,
+                                       unsigned numSelectorArgs) {
   return new (C) ObjCMethodDecl(beginLoc, endLoc,
                                 SelInfo, T, ResultTInfo, contextDecl,
                                 isInstance,
-                                isVariadic, isSynthesized, impControl);
+                                isVariadic, isSynthesized, impControl,
+                                numSelectorArgs);
 }
 
 void ObjCMethodDecl::Destroy(ASTContext &C) {
index f847becb15b878562082026c717026fd936061b5..7f80760fbfd42814ab44033da03df72ac4b70736 100644 (file)
@@ -212,6 +212,7 @@ void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
   MD->setSynthesized(Record[Idx++]);
   MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
   MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
+  MD->setNumSelectorArgs(unsigned(Record[Idx++]));
   MD->setResultType(Reader.GetType(Record[Idx++]));
   MD->setResultTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
   MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
index 42fdb45e227781b66f281df2c249bffb2198aab0..536c2c6a6fdf474c293ae48ba091f3ee39585d7e 100644 (file)
@@ -211,6 +211,7 @@ void PCHDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) {
   Record.push_back(D->getImplementationControl());
   // FIXME: stable encoding for in/out/inout/bycopy/byref/oneway
   Record.push_back(D->getObjCDeclQualifier());
+  Record.push_back(D->getNumSelectorArgs());
   Writer.AddTypeRef(D->getResultType(), Record);
   Writer.AddTypeSourceInfo(D->getResultTypeSourceInfo(), Record);
   Writer.AddSourceLocation(D->getLocEnd(), Record);
index b422c83162efc6e260ee0f60c3ccc9d88a12cd59..defda7d5dbf6ee2ef19cf8fae930703f377a365f 100644 (file)
@@ -1588,6 +1588,7 @@ Sema::DeclPtrTy Sema::ActOnMethodDeclaration(
   }
   
   ObjCMethod->setMethodParams(Context, Params.data(), Params.size());
+  ObjCMethod->setNumSelectorArgs(Sel.getNumArgs());
   ObjCMethod->setObjCDeclQualifier(
     CvtQTToAstBitMask(ReturnQT.getObjCDeclQualifier()));
   const ObjCMethodDecl *PrevMethod = 0;
diff --git a/test/CodeGenObjC/encode-cstyle-method.m b/test/CodeGenObjC/encode-cstyle-method.m
new file mode 100644 (file)
index 0000000..187c9bf
--- /dev/null
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10  -emit-llvm -o - %s | FileCheck -check-prefix LP64 %s
+// rdar: // 7445205
+
+@interface Foo 
+- (id)test:(id)one, id two;
+@end
+
+@implementation Foo
+- (id)test:(id )one, id two {return two; } @end
+
+// CHECK-LP64: internal global [11 x i8] c"@24@0:8@16