]> granicus.if.org Git - clang/commitdiff
Computed length of a __func__ identifier used in an objective-c method correctly,
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 17 Jan 2008 01:36:09 +0000 (01:36 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 17 Jan 2008 01:36:09 +0000 (01:36 +0000)
when creating its type.

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

AST/Decl.cpp
Sema/SemaExpr.cpp
include/clang/AST/DeclObjC.h

index bf1ffee83233d8c63937bb1047b271b348ab7ec1..d80b5eea80bb7a0f29a057abd21fce015876d56a 100644 (file)
@@ -549,6 +549,15 @@ ObjCMethodDecl *ObjCProtocolDecl::lookupClassMethod(Selector Sel) {
   return NULL;
 }
 
+int ObjCMethodDecl::getSynthesizedSelectorSize() const {
+  // syntesized method name is a concatenation of -/+[class-name selector]
+  // Get length of this name.
+  int length = 4;  // for '+' or '-', '[', space in between and ']'
+  length += getSelector().getName().size(); // for selector name.
+  length += strlen(getMethodContext()->getName()); // for its class name
+  return length; 
+}
+
 ObjCInterfaceDecl *const ObjCMethodDecl::getClassInterface() const {
   if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(MethodContext))
     return ID;
index c88985f75a8d40661bf729dd56bb7861fd18a599..81376a65005036f74c10630f885a1a4b15a8ae36 100644 (file)
@@ -131,7 +131,7 @@ Sema::ExprResult Sema::ActOnPreDefinedExpr(SourceLocation Loc,
   if (CurFunctionDecl)
     Length = CurFunctionDecl->getIdentifier()->getLength();
   else
-    Length = CurMethodDecl->getSelector().getName().size();
+    Length = CurMethodDecl->getSynthesizedSelectorSize();
   
   llvm::APInt LengthI(32, Length + 1);
   QualType ResTy = Context.CharTy.getQualifiedType(QualType::Const);
index 34abdb06a828c7100ef9ab6b4fb6e390acf54807..f46f324e57dd71223c3478bc8e0ad967d4e8876f 100644 (file)
@@ -116,6 +116,7 @@ public:
   ObjCInterfaceDecl *const getClassInterface() const;
   
   Selector getSelector() const { return SelName; }
+  int getSynthesizedSelectorSize() const;
   QualType getResultType() const { return MethodDeclType; }
   
   // Iterator access to formal parameters.