[cfe-commits] r56642 - in /cfe/trunk: include/clang/Basic/DiagnosticKinds.def include/clang/Parse/Action.h include/clang/Parse/Parser.h lib/Parse/ParseObjc.cpp lib/Parse/Parser.cpp lib/Sema/Sema.h lib/Sema/SemaDeclObjC.cpp test/Parser/objc-quirks.m test/Parser/prefix-attributes.m

Daniel Dunbar daniel at zuster.org
Thu Sep 25 21:48:09 PDT 2008


Author: ddunbar
Date: Thu Sep 25 23:48:09 2008
New Revision: 56642

URL: http://llvm.org/viewvc/llvm-project?rev=56642&view=rev
Log:
Parser support for prefix __attribute__ on @protocol.

Added:
    cfe/trunk/test/Parser/prefix-attributes.m
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def
    cfe/trunk/include/clang/Parse/Action.h
    cfe/trunk/include/clang/Parse/Parser.h
    cfe/trunk/lib/Parse/ParseObjc.cpp
    cfe/trunk/lib/Parse/Parser.cpp
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
    cfe/trunk/test/Parser/objc-quirks.m

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

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Thu Sep 25 23:48:09 2008
@@ -421,6 +421,8 @@
      "setter/getter expects '=' followed by name")
 DIAG(err_objc_expected_property_attr, ERROR,
      "unknown property attribute detected")
+DIAG(err_objc_unexpected_attr, ERROR,
+     "prefix attribute must be followed by an interface or protocol")
 DIAG(err_objc_property_attr_mutually_exclusive, ERROR,
      "property attributes '%0' and '%1' are mutually exclusive")
 DIAG(warn_objc_property_no_assignment_attribute, WARNING,

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

==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Thu Sep 25 23:48:09 2008
@@ -694,7 +694,8 @@
                                               SourceLocation ProtocolLoc,
                                               DeclTy * const *ProtoRefs,
                                               unsigned NumProtoRefs,
-                                              SourceLocation EndProtoLoc) {
+                                              SourceLocation EndProtoLoc,
+                                              AttributeList *AttrList) {
     return 0;
   }
   // ActOnStartCategoryInterface - this action is called immdiately after

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

==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Thu Sep 25 23:48:09 2008
@@ -331,7 +331,8 @@
                                    SourceLocation &EndProtoLoc);
   void ParseObjCInterfaceDeclList(DeclTy *interfaceDecl,
                                   tok::ObjCKeywordKind contextKey);
-  DeclTy *ParseObjCAtProtocolDeclaration(SourceLocation atLoc);
+  DeclTy *ParseObjCAtProtocolDeclaration(SourceLocation atLoc,
+                                         AttributeList *prefixAttrs = 0);
   
   DeclTy *ObjCImpDecl;
 

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

==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Thu Sep 25 23:48:09 2008
@@ -920,7 +920,8 @@
 ///   "@protocol identifier ;" should be resolved as "@protocol
 ///   identifier-list ;": objc-interface-decl-list may not start with a
 ///   semicolon in the first alternative if objc-protocol-refs are omitted.
-Parser::DeclTy *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc) {
+Parser::DeclTy *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc,
+                                               AttributeList *attrList) {
   assert(Tok.isObjCAtKeyword(tok::objc_protocol) &&
          "ParseObjCAtProtocolDeclaration(): Expected @protocol");
   ConsumeToken(); // the "protocol" identifier
@@ -978,7 +979,7 @@
   DeclTy *ProtoType =
     Actions.ActOnStartProtocolInterface(AtLoc, protocolName, nameLoc,
                                         &ProtocolRefs[0], ProtocolRefs.size(),
-                                        EndProtoLoc);
+                                        EndProtoLoc, attrList);
   ParseObjCInterfaceDeclList(ProtoType, tok::objc_protocol);
 
   // The @ sign was already consumed by ParseObjCInterfaceDeclList().

Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=56642&r1=56641&r2=56642&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Thu Sep 25 23:48:09 2008
@@ -393,17 +393,22 @@
     return Actions.ParsedFreeStandingDeclSpec(CurScope, DS);
   }
 
-  // ObjC2 allows prefix attributes on class interfaces.
+  // ObjC2 allows prefix attributes on class interfaces and protocols.
+  // FIXME: This still needs better diagnostics. We should only accept
+  // attributes here, no types, etc.
   if (getLang().ObjC2 && Tok.is(tok::at)) {
     SourceLocation AtLoc = ConsumeToken(); // the "@"
-    if (!Tok.isObjCAtKeyword(tok::objc_interface)) {
-      Diag(Tok, diag::err_objc_expected_property_attr);//FIXME:better diagnostic
+    if (!Tok.isObjCAtKeyword(tok::objc_interface) && 
+        !Tok.isObjCAtKeyword(tok::objc_protocol)) {
+      Diag(Tok, diag::err_objc_unexpected_attr);
       SkipUntil(tok::semi); // FIXME: better skip?
       return 0;
     }
     const char *PrevSpec = 0;
     if (DS.SetTypeSpecType(DeclSpec::TST_unspecified, AtLoc, PrevSpec))
       Diag(AtLoc, diag::err_invalid_decl_spec_combination, PrevSpec);
+    if (Tok.isObjCAtKeyword(tok::objc_protocol))
+      return ParseObjCAtProtocolDeclaration(AtLoc, DS.getAttributes());
     return ParseObjCAtInterfaceDeclaration(AtLoc, DS.getAttributes());
   }
 

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

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Thu Sep 25 23:48:09 2008
@@ -686,7 +686,8 @@
                     SourceLocation AtProtoInterfaceLoc,
                     IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
                     DeclTy * const *ProtoRefNames, unsigned NumProtoRefs,
-                    SourceLocation EndProtoLoc);
+                    SourceLocation EndProtoLoc,
+                    AttributeList *AttrList);
   
   virtual DeclTy *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
                                               IdentifierInfo *ClassName,

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=56642&r1=56641&r2=56642&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Thu Sep 25 23:48:09 2008
@@ -173,7 +173,9 @@
                                   SourceLocation ProtocolLoc,
                                   DeclTy * const *ProtoRefs,
                                   unsigned NumProtoRefs,
-                                  SourceLocation EndProtoLoc) {
+                                  SourceLocation EndProtoLoc,
+                                  AttributeList *AttrList) {
+  // FIXME: Deal with AttrList.
   assert(ProtocolName && "Missing protocol identifier");
   ObjCProtocolDecl *PDecl = ObjCProtocols[ProtocolName];
   if (PDecl) {

Modified: cfe/trunk/test/Parser/objc-quirks.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-quirks.m?rev=56642&r1=56641&r2=56642&view=diff

==============================================================================
--- cfe/trunk/test/Parser/objc-quirks.m (original)
+++ cfe/trunk/test/Parser/objc-quirks.m Thu Sep 25 23:48:09 2008
@@ -1,3 +1,4 @@
 // RUN: clang -fsyntax-only -verify %s
 
-int @"s" = 5;  // expected-error {{unknown}}
+// FIXME: This is a horrible error message here. Fix.
+int @"s" = 5;  // expected-error {{prefix attribute must be}}

Added: cfe/trunk/test/Parser/prefix-attributes.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/prefix-attributes.m?rev=56642&view=auto

==============================================================================
--- cfe/trunk/test/Parser/prefix-attributes.m (added)
+++ cfe/trunk/test/Parser/prefix-attributes.m Thu Sep 25 23:48:09 2008
@@ -0,0 +1,8 @@
+// RUN: clang -verify -fsyntax-only %s
+
+__attribute__((deprecated)) @class B; // expected-error {{prefix attribute must be followed by an interface or protocol}}
+
+__attribute__((deprecated)) @interface A @end
+__attribute__((deprecated)) @protocol P0;
+__attribute__((deprecated)) @protocol P1
+ at end





More information about the cfe-commits mailing list