[cfe-commits] r41880 - in /cfe/trunk: AST/Decl.cpp Parse/ParseObjc.cpp Sema/Sema.h Sema/SemaDecl.cpp include/clang/AST/Decl.h

Fariborz Jahanian fjahanian at apple.com
Wed Sep 12 11:23:47 PDT 2007


Author: fjahanian
Date: Wed Sep 12 13:23:47 2007
New Revision: 41880

URL: http://llvm.org/viewvc/llvm-project?rev=41880&view=rev
Log:
Patch for building method declaration nodes. Also fixed a segfault in cocoa.m due
to use of @property.

Modified:
    cfe/trunk/AST/Decl.cpp
    cfe/trunk/Parse/ParseObjc.cpp
    cfe/trunk/Sema/Sema.h
    cfe/trunk/Sema/SemaDecl.cpp
    cfe/trunk/include/clang/AST/Decl.h

Modified: cfe/trunk/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Decl.cpp?rev=41880&r1=41879&r2=41880&view=diff

==============================================================================
--- cfe/trunk/AST/Decl.cpp (original)
+++ cfe/trunk/AST/Decl.cpp Wed Sep 12 13:23:47 2007
@@ -164,6 +164,22 @@
   return 0;
 }
 
+void ObjcMethodDecl::setMethodParams(ParmVarDecl **NewParamInfo, 
+		       unsigned NumParams) {
+  assert(ParamInfo == 0 && "Already has param info!");
+
+  // Zero params -> null pointer.
+  if (NumParams) {
+    ParamInfo = new ParmVarDecl*[NumParams];
+    memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams);
+    NumMethodParams = NumParams;
+  }
+}
+
+ObjcMethodDecl::~ObjcMethodDecl() {
+  delete[] ParamInfo;
+}
+
 /// addObjcMethods - Insert instance and methods declarations into
 /// ObjcInterfaceDecl's InsMethods and ClsMethods fields.
 ///

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

==============================================================================
--- cfe/trunk/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/Parse/ParseObjc.cpp Wed Sep 12 13:23:47 2007
@@ -229,7 +229,7 @@
         ConsumeToken();
         continue;
       } else if (ocKind == tok::objc_property) {
-        ParseObjCPropertyDecl(0/*FIXME*/);
+        ParseObjCPropertyDecl(interfaceDecl);
         continue;
       } else {
         Diag(Tok, diag::err_objc_illegal_interface_qual);

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

==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Wed Sep 12 13:23:47 2007
@@ -360,6 +360,13 @@
 
   virtual void ObjcAddMethodsToClass(DeclTy *ClassDecl, 
 				     DeclTy **allMethods, unsigned allNum);
+  virtual DeclTy *ObjcBuildMethodDeclaration(SourceLocation MethodLoc, 
+	            tok::TokenKind MethodType, TypeTy *ReturnType,
+     		    ObjcKeywordInfo *Keywords, unsigned NumKeywords, 
+     		    AttributeList *AttrList);
+  virtual DeclTy *ObjcBuildMethodDeclaration(SourceLocation MethodLoc, 
+ 	     	    tok::TokenKind MethodType, TypeTy *ReturnType,
+     		    IdentifierInfo *SelectorName, AttributeList *AttrList);
                                       
   virtual void ObjcAddInstanceVariable(DeclTy *ClassDec, DeclTy *Ivar,
                                        tok::ObjCKeywordKind visibility);

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

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Wed Sep 12 13:23:47 2007
@@ -1197,8 +1197,10 @@
 
 void Sema::ObjcAddMethodsToClass(DeclTy *ClassDecl, 
 				 DeclTy **allMethods, unsigned allNum) { 
-  // FIXME: Add method insertion code here.
-#if 0
+  // FIXME: Fix this when we can handle methods declared in protocols.
+  // See Parser::ParseObjCAtProtocolDeclaration
+  if (!ClassDecl)
+    return;
   ObjcInterfaceDecl *Interface = cast<ObjcInterfaceDecl>(
 				   static_cast<Decl*>(ClassDecl));
   llvm::SmallVector<ObjcMethodDecl*, 32> insMethods;
@@ -1215,10 +1217,46 @@
   }
   Interface->ObjcAddMethods(&insMethods[0], insMethods.size(), 
 			    &clsMethods[0], clsMethods.size());
-#endif
   return;
 }
 
+Sema::DeclTy *Sema::ObjcBuildMethodDeclaration(SourceLocation MethodLoc, 
+                      tok::TokenKind MethodType, TypeTy *ReturnType,
+                      ObjcKeywordInfo *Keywords, unsigned NumKeywords,
+                      AttributeList *AttrList) {
+  assert(NumKeywords && "Selector must be specified");
+  // FIXME: SelectorName to be changed to comform to objc's abi for method names
+  IdentifierInfo *SelectorName = Keywords[0].SelectorName;
+  llvm::SmallVector<ParmVarDecl*, 16> Params;
+
+  for (unsigned i = 0; i < NumKeywords; i++) {
+    ObjcKeywordInfo *arg = &Keywords[i];
+    // FIXME: arg->AttrList must be stored too!
+    ParmVarDecl* Param = new ParmVarDecl(arg->ColonLoc, arg->ArgumentName, 
+					 QualType::getFromOpaquePtr(arg->TypeInfo), 
+					 VarDecl::None, 0);
+    // FIXME: 'InvalidType' does not get set by caller yet.
+    if (arg->InvalidType)
+      Param->setInvalidDecl();
+    Params.push_back(Param);
+  }
+  QualType resultDeclType = QualType::getFromOpaquePtr(ReturnType);
+  ObjcMethodDecl* ObjcMethod =  new ObjcMethodDecl(MethodLoc, 
+				      SelectorName, resultDeclType, 
+				      0, -1, AttrList, MethodType == tok::minus);
+  ObjcMethod->setMethodParams(&Params[0], NumKeywords);
+  return ObjcMethod;
+}
+
+Sema::DeclTy *Sema::ObjcBuildMethodDeclaration(SourceLocation MethodLoc,  
+                      tok::TokenKind MethodType, TypeTy *ReturnType,
+                      IdentifierInfo *SelectorName, AttributeList *AttrList) {
+  // FIXME: SelectorName to be changed to comform to objc's abi for method names
+  QualType resultDeclType = QualType::getFromOpaquePtr(ReturnType);
+  return new ObjcMethodDecl(MethodLoc, SelectorName, resultDeclType, 0, -1,
+			    AttrList, MethodType == tok::minus);
+}
+
 Sema::DeclTy *Sema::ParseEnumConstant(Scope *S, DeclTy *theEnumDecl,
                                       DeclTy *lastEnumConst,
                                       SourceLocation IdLoc, IdentifierInfo *Id,

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

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Wed Sep 12 13:23:47 2007
@@ -583,19 +583,21 @@
 class ObjcMethodDecl : public Decl {
 public:
   ObjcMethodDecl(SourceLocation L, IdentifierInfo *Id, QualType T,
+		 ParmVarDecl **paramInfo = 0, int numParams=-1,
 		 AttributeList *M = 0, bool isInstance = true, 
 		 Decl *PrevDecl = 0)
-    : Decl(ObjcMethod, L, Id, PrevDecl), MethodDeclType(T), ParamInfo(0), 
+    : Decl(ObjcMethod, L, Id, PrevDecl), MethodDeclType(T), 
+      ParamInfo(paramInfo), NumMethodParams(numParams),
       MethodAttrs(M), IsInstance(isInstance) {}
 
   virtual ~ObjcMethodDecl();
   QualType getMethodType() const { return MethodDeclType; }
-  unsigned getNumMethodParams() const;
+  unsigned getNumMethodParams() const { return NumMethodParams; }
   ParmVarDecl *getMethodParamDecl(unsigned i) {
     assert(i < getNumMethodParams() && "Illegal param #");
     return ParamInfo[i];
   }
-  void setParams(ParmVarDecl **NewParamInfo, unsigned NumParams);
+  void setMethodParams(ParmVarDecl **NewParamInfo, unsigned NumParams);
 
   AttributeList *getMethodAttrs() const {return MethodAttrs;}
   bool isInstance() const { return IsInstance; }
@@ -610,6 +612,7 @@
   /// ParamInfo - new[]'d array of pointers to VarDecls for the formal
   /// parameters of this Method.  This is null if there are no formals.  
   ParmVarDecl **ParamInfo;
+  int NumMethodParams;  // -1 if no parameters
   
   /// List of attributes for this method declaration.
   AttributeList *MethodAttrs;





More information about the cfe-commits mailing list