[cfe-commits] r42649 - in /cfe/trunk: Parse/ParseDecl.cpp Sema/Sema.h Sema/SemaDecl.cpp clang.xcodeproj/project.pbxproj include/clang/Basic/DiagnosticKinds.def include/clang/Parse/Action.h test/Sema/undefined-protocol-type-1.m

Fariborz Jahanian fjahanian at apple.com
Fri Oct 5 14:01:53 PDT 2007


Author: fjahanian
Date: Fri Oct  5 16:01:53 2007
New Revision: 42649

URL: http://llvm.org/viewvc/llvm-project?rev=42649&view=rev
Log:
This is the first patch toward supporting protocol conforming
objective-c types. It also removes use of Scope* parameter in
getObjCProtocolDecl.

Added:
    cfe/trunk/test/Sema/undefined-protocol-type-1.m
Modified:
    cfe/trunk/Parse/ParseDecl.cpp
    cfe/trunk/Sema/Sema.h
    cfe/trunk/Sema/SemaDecl.cpp
    cfe/trunk/clang.xcodeproj/project.pbxproj
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def
    cfe/trunk/include/clang/Parse/Action.h

Modified: cfe/trunk/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseDecl.cpp?rev=42649&r1=42648&r2=42649&view=diff

==============================================================================
--- cfe/trunk/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/Parse/ParseDecl.cpp Fri Oct  5 16:01:53 2007
@@ -409,6 +409,10 @@
             if (Tok.getKind() == tok::less) {
               llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs;
               ParseObjCProtocolReferences(ProtocolRefs);
+              Actions.ActOnFindProtocolDeclaration(CurScope,
+                                                   Loc,
+                                                   &ProtocolRefs[0],
+                                                   ProtocolRefs.size());
             }
             continue;
           }

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

==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Fri Oct  5 16:01:53 2007
@@ -429,6 +429,11 @@
                                                   SourceLocation AtProtocolLoc,
                                                   IdentifierInfo **IdentList,
                                                   unsigned NumElts);
+  
+  virtual DeclTy **ActOnFindProtocolDeclaration(Scope *S,
+                                                SourceLocation TypeLoc,
+                                                IdentifierInfo **ProtocolId,
+                                                unsigned NumProtocols);
 
   virtual void ActOnAddMethodsToObjcDecl(Scope* S, DeclTy *ClassDecl, 
 				         DeclTy **allMethods, unsigned allNum);

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

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Fri Oct  5 16:01:53 2007
@@ -104,8 +104,14 @@
                                             IdentifierInfo *Id, 
                                             SourceLocation IdLoc) {
   // Note that Protocols have their own namespace.
-  ScopedDecl *PrDecl = LookupScopedDecl(Id, Decl::IDNS_Protocol, 
-                                        IdLoc, S);
+  ScopedDecl *PrDecl = NULL;
+  for (ScopedDecl *D = Id->getFETokenInfo<ScopedDecl>(); D; D = D->getNext()) {
+    if (D->getIdentifierNamespace() == Decl::IDNS_Protocol) {
+      PrDecl = D;
+      break;
+    }
+  }
+  
   if (PrDecl && !isa<ObjcProtocolDecl>(PrDecl))
     PrDecl = 0;
   return cast_or_null<ObjcProtocolDecl>(static_cast<Decl*>(PrDecl));
@@ -1007,6 +1013,24 @@
   return PDecl;
 }
 
+/// ActOnFindProtocolDeclaration - This routine looks for a previously
+/// declared protocol and returns it. If not found, issues diagnostic.
+/// Will build a list of previously protocol declarations found in the list.
+Action::DeclTy **
+Sema::ActOnFindProtocolDeclaration(Scope *S,
+                                   SourceLocation TypeLoc,
+                                   IdentifierInfo **ProtocolId,
+                                   unsigned NumProtocols) {
+  for (unsigned i = 0; i != NumProtocols; ++i) {
+    ObjcProtocolDecl *PDecl = getObjCProtocolDecl(S, ProtocolId[i], 
+                                                  TypeLoc);
+    if (!PDecl)
+      Diag(TypeLoc, diag::err_undeclared_protocol, 
+           ProtocolId[i]->getName());
+  }
+  return 0;
+}
+
 /// ActOnForwardProtocolDeclaration - 
 /// Scope will always be top level file scope. 
 Action::DeclTy *

Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=42649&r1=42648&r2=42649&view=diff

==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Fri Oct  5 16:01:53 2007
@@ -242,7 +242,7 @@
 		DE06B73D0A8307640050E87E /* LangOptions.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = LangOptions.h; sourceTree = "<group>"; };
 		DE06BECA0A854E4B0050E87E /* Scope.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = Scope.h; path = clang/Parse/Scope.h; sourceTree = "<group>"; };
 		DE06D42F0A8BB52D0050E87E /* Parser.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = Parser.cpp; path = Parse/Parser.cpp; sourceTree = "<group>"; };
-		DE06E8130A8FF9330050E87E /* Action.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = Action.h; path = clang/Parse/Action.h; sourceTree = "<group>"; };
+		DE06E8130A8FF9330050E87E /* Action.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 2; lastKnownFileType = sourcecode.c.h; name = Action.h; path = clang/Parse/Action.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
 		DE0FCA620A95859D00248FD5 /* Expr.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = Expr.h; path = clang/AST/Expr.h; sourceTree = "<group>"; };
 		DE0FCB330A9C21F100248FD5 /* Expr.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = Expr.cpp; path = AST/Expr.cpp; sourceTree = "<group>"; };
 		DE1732FF0B068B700080B521 /* ASTContext.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ASTContext.cpp; path = AST/ASTContext.cpp; sourceTree = "<group>"; };
@@ -737,6 +737,7 @@
 		08FB7793FE84155DC02AAC07 /* Project object */ = {
 			isa = PBXProject;
 			buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
+			compatibilityVersion = "Xcode 2.4";
 			hasScannedForEncodings = 1;
 			mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
 			projectDirPath = "";

Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=42649&r1=42648&r2=42649&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Fri Oct  5 16:01:53 2007
@@ -442,6 +442,8 @@
      "duplicate declaration of method '%0'")
 DIAG(err_previous_declaration, ERROR,
      "previous declaration is here")
+DIAG(err_undeclared_protocol, ERROR,
+     "cannot find protocol declaration for '%0'")
 
 
 //===----------------------------------------------------------------------===//

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

==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Fri Oct  5 16:01:53 2007
@@ -555,6 +555,17 @@
     return 0;
   }
   
+  /// ActOnFindProtocolDeclaration - This routine looks for a previously
+  /// declared protocol and returns it. If not found, issues diagnostic.
+  /// Will build a list of previously protocol declarations found in the list.
+  virtual DeclTy **ActOnFindProtocolDeclaration(Scope *S,
+                                                SourceLocation TypeLoc,
+                                                IdentifierInfo **ProtocolId,
+                                                unsigned NumProtocols) {
+    return 0;
+  }
+                                               
+                                               
   //===----------------------- Obj-C Expressions --------------------------===//
   virtual ExprResult ParseObjCStringLiteral(ExprTy *string) {
     return 0;

Added: cfe/trunk/test/Sema/undefined-protocol-type-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/undefined-protocol-type-1.m?rev=42649&view=auto

==============================================================================
--- cfe/trunk/test/Sema/undefined-protocol-type-1.m (added)
+++ cfe/trunk/test/Sema/undefined-protocol-type-1.m Fri Oct  5 16:01:53 2007
@@ -0,0 +1,9 @@
+// RUN: clang -fsyntax-only -verify %s
+
+ at protocol p1, p4;
+ at protocol p2 @end
+
+ at interface T
+- (T<p2, p3, p1, p4>*) meth;  // expected-error {{cannot find protocol declaration for 'p3'}}
+- (T<p2, p3, p1, p4>*) meth;  // expected-error {{cannot find protocol declaration for 'p3'}}
+ at end





More information about the cfe-commits mailing list