[cfe-commits] r43957 - in /cfe/trunk: Parse/ParseObjc.cpp Sema/Sema.h Sema/SemaDecl.cpp Sema/SemaType.cpp include/clang/AST/DeclObjC.h include/clang/Parse/Action.h include/clang/Parse/Parser.h test/Sema/method-def-1.m

Fariborz Jahanian fjahanian at apple.com
Fri Nov 9 11:52:12 PST 2007


Author: fjahanian
Date: Fri Nov  9 13:52:12 2007
New Revision: 43957

URL: http://llvm.org/viewvc/llvm-project?rev=43957&view=rev
Log:
Added class context to method declarations. Provide "interface *" type
to 'self' method of instance methods.

Added:
    cfe/trunk/test/Sema/method-def-1.m
Modified:
    cfe/trunk/Parse/ParseObjc.cpp
    cfe/trunk/Sema/Sema.h
    cfe/trunk/Sema/SemaDecl.cpp
    cfe/trunk/Sema/SemaType.cpp
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/include/clang/Parse/Action.h
    cfe/trunk/include/clang/Parse/Parser.h

Modified: cfe/trunk/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseObjc.cpp?rev=43957&r1=43956&r2=43957&view=diff

==============================================================================
--- cfe/trunk/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/Parse/ParseObjc.cpp Fri Nov  9 13:52:12 2007
@@ -416,7 +416,7 @@
   tok::TokenKind methodType = Tok.getKind();  
   SourceLocation mLoc = ConsumeToken();
   
-  DeclTy *MDecl = ParseObjCMethodDecl(mLoc, methodType, MethodImplKind);
+  DeclTy *MDecl = ParseObjCMethodDecl(mLoc, methodType, IDecl, MethodImplKind);
   // Since this rule is used for both method declarations and definitions,
   // the caller is (optionally) responsible for consuming the ';'.
   return MDecl;
@@ -550,7 +550,8 @@
 ///     __attribute__((unused))
 ///
 Parser::DeclTy *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
-                                            tok::TokenKind mType, 
+                                            tok::TokenKind mType,
+                                            DeclTy *IDecl,
 					    tok::ObjCKeywordKind MethodImplKind)
 {
   // Parse the return type.
@@ -574,7 +575,7 @@
     
     Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent);
     return Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(),
-                                          mType, DSRet, ReturnType, Sel,
+                                          mType, IDecl, DSRet, ReturnType, Sel,
                                           0, 0, 0, MethodAttrs, MethodImplKind);
   }
 
@@ -645,7 +646,7 @@
   Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(),
                                                    &KeyIdents[0]);
   return Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(),
-                                        mType, DSRet, ReturnType, Sel, 
+                                        mType, IDecl, DSRet, ReturnType, Sel, 
                                         &ArgTypeQuals[0], &KeyTypes[0], 
                                         &ArgNames[0],
                                         MethodAttrs, MethodImplKind);

Modified: cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.h?rev=43957&r1=43956&r2=43957&view=diff

==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Fri Nov  9 13:52:12 2007
@@ -552,7 +552,8 @@
   virtual DeclTy *ActOnMethodDeclaration(
     SourceLocation BeginLoc, // location of the + or -.
     SourceLocation EndLoc,   // location of the ; or {.
-    tok::TokenKind MethodType, ObjcDeclSpec &ReturnQT, TypeTy *ReturnType, 
+    tok::TokenKind MethodType, 
+    DeclTy *ClassDecl, ObjcDeclSpec &ReturnQT, TypeTy *ReturnType, 
     Selector Sel,
     // optional arguments. The number of types/arguments is obtained
     // from the Sel.getNumArgs().

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

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Fri Nov  9 13:52:12 2007
@@ -1047,11 +1047,14 @@
   llvm::SmallVector<ParmVarDecl*, 16> Params;
   ParmVarDecl *PDecl;
   // Insert the invisible arguments!
-  if (MDecl->isInstance())
-    // FIXME: type is wrong.
+  if (MDecl->isInstance()) {
+    QualType selfTy = Context.getObjcInterfaceType(MDecl->getClassInterface());
+    selfTy = Context.getPointerType(selfTy);
     PDecl = new ParmVarDecl(SourceLocation(/*FIXME*/), 
                             &Context.Idents.get("self"),
-                            Context.getObjcIdType(), VarDecl::None, 0);
+                            selfTy,
+                            VarDecl::None, 0);
+  }
   else
     PDecl = new ParmVarDecl(SourceLocation(/*FIXME*/), 
                             &Context.Idents.get("self"),
@@ -2179,7 +2182,8 @@
 
 Sema::DeclTy *Sema::ActOnMethodDeclaration(
     SourceLocation MethodLoc, SourceLocation EndLoc,
-    tok::TokenKind MethodType, ObjcDeclSpec &ReturnQT, TypeTy *ReturnType,
+    tok::TokenKind MethodType, DeclTy *ClassDecl,
+    ObjcDeclSpec &ReturnQT, TypeTy *ReturnType,
     Selector Sel,
     // optional arguments. The number of types/arguments is obtained
     // from the Sel.getNumArgs().
@@ -2207,9 +2211,22 @@
     resultDeclType = QualType::getFromOpaquePtr(ReturnType);
   else // get the type for "id".
     resultDeclType = Context.getObjcIdType();
-
+  
+  Decl *CDecl = static_cast<Decl*>(ClassDecl);
+  ObjcInterfaceDecl *IDecl = 0;
+  if (isa<ObjcInterfaceDecl>(CDecl))
+    IDecl = cast<ObjcInterfaceDecl>(CDecl);
+  else if (isa<ObjcCategoryDecl>(CDecl))
+    IDecl = cast<ObjcCategoryDecl>(CDecl)->getClassInterface();
+  else if (isa<ObjcImplementationDecl>(CDecl))
+    IDecl = cast<ObjcImplementationDecl>(CDecl)->getClassInterface();
+  else if (isa<ObjcCategoryImplDecl>(CDecl))
+    IDecl = cast<ObjcCategoryImplDecl>(CDecl)->getClassInterface();
+  
   ObjcMethodDecl* ObjcMethod =  new ObjcMethodDecl(MethodLoc, EndLoc, Sel,
-                                      resultDeclType, 0, -1, AttrList, 
+                                      resultDeclType,
+                                      IDecl,
+                                      0, -1, AttrList, 
                                       MethodType == tok::minus,
                                       MethodDeclKind == tok::objc_optional ? 
                                       ObjcMethodDecl::Optional : 

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

==============================================================================
--- cfe/trunk/Sema/SemaType.cpp (original)
+++ cfe/trunk/Sema/SemaType.cpp Fri Nov  9 13:52:12 2007
@@ -333,9 +333,11 @@
   llvm::SmallVector<QualType, 16> ArgTys;
   
   // Add the first two invisible argument types for self and _cmd.
-  if (MDecl->isInstance())
-    // FIXME: interface-name *
-    ArgTys.push_back(Context.getObjcIdType());
+  if (MDecl->isInstance()) {
+    QualType selfTy = Context.getObjcInterfaceType(MDecl->getClassInterface());
+    selfTy = Context.getPointerType(selfTy);
+    ArgTys.push_back(selfTy);
+  }
   else
     ArgTys.push_back(Context.getObjcIdType());
   ArgTys.push_back(Context.getObjcSelType());

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Fri Nov  9 13:52:12 2007
@@ -239,6 +239,9 @@
   /// in, inout, etc.
   ObjcDeclQualifier objcDeclQualifier : 6;
   
+  // @interface decl this Method belongs to.
+  ObjcInterfaceDecl *ClassInterface;
+  
   // A unigue name for this method.
   Selector SelName;
   
@@ -256,6 +259,7 @@
 public:
   ObjcMethodDecl(SourceLocation beginLoc, SourceLocation endLoc,
                  Selector SelInfo, QualType T,
+                 ObjcInterfaceDecl *interfaceDecl,
                  ParmVarDecl **paramInfo = 0, int numParams=-1,
                  AttributeList *M = 0, bool isInstance = true,
                  ImplementationControl impControl = None,
@@ -263,6 +267,7 @@
     : Decl(ObjcMethod, beginLoc),
       IsInstance(isInstance), DeclImplementation(impControl),
       objcDeclQualifier(OBJC_TQ_None),
+      ClassInterface(interfaceDecl),
       SelName(SelInfo), MethodDeclType(T), 
       ParamInfo(paramInfo), NumMethodParams(numParams),
       MethodAttrs(M), EndLoc(endLoc) {}
@@ -275,6 +280,8 @@
   SourceLocation getLocStart() const { return getLocation(); }
   SourceLocation getLocEnd() const { return EndLoc; }
   
+  ObjcInterfaceDecl *const getClassInterface() const { return ClassInterface; }
+  
   Selector getSelector() const { return SelName; }
   QualType getResultType() const { return MethodDeclType; }
 

Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=43957&r1=43956&r2=43957&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Fri Nov  9 13:52:12 2007
@@ -561,6 +561,7 @@
     SourceLocation BeginLoc,   // location of the + or -.
     SourceLocation EndLoc,     // location of the ; or {.
     tok::TokenKind MethodType, // tok::minus for instance, tok::plus for class.
+    DeclTy *ClassDecl,         // class this methods belongs to.
     ObjcDeclSpec &ReturnQT,    // for return type's in inout etc.
     TypeTy *ReturnType,        // the method return type.
     Selector Sel,              // a unique name for the method.

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=43957&r1=43956&r2=43957&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Fri Nov  9 13:52:12 2007
@@ -297,6 +297,7 @@
   DeclTy *ParseObjCMethodPrototype(DeclTy *classOrCat,
    	    tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword);
   DeclTy *ParseObjCMethodDecl(SourceLocation mLoc, tok::TokenKind mType,
+                              DeclTy *classDecl,
             tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword);
   void ParseObjCPropertyAttribute(ObjcDeclSpec &DS);
   DeclTy *ParseObjCPropertyDecl(DeclTy *interfaceDecl, SourceLocation AtLoc);

Added: cfe/trunk/test/Sema/method-def-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/method-def-1.m?rev=43957&view=auto

==============================================================================
--- cfe/trunk/test/Sema/method-def-1.m (added)
+++ cfe/trunk/test/Sema/method-def-1.m Fri Nov  9 13:52:12 2007
@@ -0,0 +1,8 @@
+ at interface foo
+- (int)meth;
+ at end
+
+ at implementation foo
+- (int) meth { return [self meth]; }
+ at end
+





More information about the cfe-commits mailing list