[cfe-commits] r51972 - in /cfe/trunk: lib/Parse/ParseDecl.cpp test/Sema/bogus-gcc-protocol-extension.m

Steve Naroff snaroff at apple.com
Wed Jun 4 17:02:44 PDT 2008


Author: snaroff
Date: Wed Jun  4 19:02:44 2008
New Revision: 51972

URL: http://llvm.org/viewvc/llvm-project?rev=51972&view=rev
Log:
Support "<p>" as a short-hand for "id<p>". Here's a comment from GCC (the only documentation I could find on it).

/* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" - nisse at lysator.liu.se.  */

This commit adds the parser magic. The type associated with <p> is still incorrect. Will discuss with Chris.

Added:
    cfe/trunk/test/Sema/bogus-gcc-protocol-extension.m
Modified:
    cfe/trunk/lib/Parse/ParseDecl.cpp

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

==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Wed Jun  4 19:02:44 2008
@@ -323,7 +323,7 @@
   
   // Validate declspec for type-name.
   unsigned Specs = DS.getParsedSpecifiers();
-  if (Specs == DeclSpec::PQ_None)
+  if (Specs == DeclSpec::PQ_None && !DS.getNumProtocolQualifiers())
     Diag(Tok, diag::err_typename_requires_specqual);
   
   // Issue diagnostic and remove storage class if present.
@@ -548,6 +548,21 @@
     case tok::kw_inline:
       isInvalid = DS.SetFunctionSpecInline(Loc, PrevSpec);
       break;
+      
+    // Gross GCC-ism that we are forced support. FIXME: make an extension?
+    case tok::less:
+      if (!DS.hasTypeSpecifier()) {
+        SourceLocation endProtoLoc;
+        llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs;
+        ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc);
+        llvm::SmallVector<DeclTy *, 8> *ProtocolDecl = 
+                new llvm::SmallVector<DeclTy *, 8>;
+        DS.setProtocolQualifiers(ProtocolDecl);
+        Actions.FindProtocolDeclaration(Loc, 
+                  &ProtocolRefs[0], ProtocolRefs.size(),
+                  *ProtocolDecl);
+      }
+      continue;
     }
     // If the specifier combination wasn't legal, issue a diagnostic.
     if (isInvalid) {
@@ -872,6 +887,8 @@
   case tok::kw___attribute:
     // GNU typeof support.
   case tok::kw_typeof:
+    // GNU bizarre protocol extension. FIXME: make an extension?
+  case tok::less:
   
     // type-specifiers
   case tok::kw_short:
@@ -962,6 +979,9 @@
     
     // GNU attributes.
   case tok::kw___attribute:
+  
+    // GNU bizarre protocol extension. FIXME: make an extension?
+  case tok::less:
     return true;
     
     // typedef-name

Added: cfe/trunk/test/Sema/bogus-gcc-protocol-extension.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/bogus-gcc-protocol-extension.m?rev=51972&view=auto

==============================================================================
--- cfe/trunk/test/Sema/bogus-gcc-protocol-extension.m (added)
+++ cfe/trunk/test/Sema/bogus-gcc-protocol-extension.m Wed Jun  4 19:02:44 2008
@@ -0,0 +1,300 @@
+// RUN: clang -fsyntax-only -verify %s
+typedef struct objc_selector *SEL;
+typedef signed char BOOL;
+typedef int NSInteger;
+typedef unsigned int NSUInteger;
+typedef struct _NSZone NSZone;
+ at class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
+ at protocol NSObject
+- (BOOL)isEqual:(id)object;
+- (BOOL)conformsToProtocol:(Protocol *)aProtocol;
+ at end
+
+ at protocol NSCopying
+- (id)copyWithZone:(NSZone *)zone;
+ at end
+
+ at protocol NSMutableCopying
+- (id)mutableCopyWithZone:(NSZone *)zone;
+ at end
+
+ at protocol NSCoding
+- (void)encodeWithCoder:(NSCoder *)aCoder;
+ at end
+
+ at interface NSObject <NSObject> {}
+
+- (void)dealloc;
+ at end
+
+extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone);
+
+typedef struct _NSSize {} NSRect;
+typedef struct {} NSFastEnumerationState;
+
+ at protocol NSFastEnumeration
+- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len;
+ at end
+
+ at class NSString;
+ at interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding>  
+- (NSUInteger)length;
+- (BOOL)isEqualToString:(NSString *)aString;
+ at end
+
+ at interface NSSimpleCString : NSString {} @end
+
+ at interface NSConstantString : NSSimpleCString @end
+
+extern void *_NSConstantStringClassReference;
+
+ at interface NSSet : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration>
+- (NSUInteger)count;
+ at end
+
+ at interface NSMutableSet : NSSet
+- (void)addObject:(id)object;
+ at end
+
+ at class NSArray, NSDictionary, NSMapTable;
+ at interface NSResponder : NSObject <NSCoding> {} @end
+
+ at protocol NSAnimatablePropertyContainer    
+- (id)animator;
+ at end
+
+extern NSString *NSAnimationTriggerOrderIn ;
+ at interface NSView : NSResponder  <NSAnimatablePropertyContainer> {} @end
+
+extern NSString * const NSFullScreenModeAllScreens;
+typedef NSUInteger NSControlTint;
+
+ at interface NSCell : NSObject <NSCopying, NSCoding> {}
+- (NSRect)imageRectForBounds:(NSRect)theRect;
+ at end
+
+ at protocol NSValidatedUserInterfaceItem
+- (SEL)action;
+ at end
+
+ at protocol NSUserInterfaceValidations
+- (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)anItem;
+ at end
+
+ at class NSCell, NSFont, NSTextView, NSNotification, NSAttributedString, NSFormatter;
+ at interface NSControl : NSView {} @end
+
+ at class NSColor, NSClipView, NSRulerView, NSScroller;
+ at interface NSWindowController : NSResponder <NSCoding> {} @end
+
+ at class NSTableHeaderView;
+ at class NSTableColumn;
+ at interface NSTableView : NSControl <NSUserInterfaceValidations> {}
+
+- (NSInteger)columnWithIdentifier:(id)identifier;
+- (NSRect)frameOfCellAtColumn:(NSInteger)column row:(NSInteger)row;
+ at end
+
+ at class NSButtonCell;
+ at interface NSOutlineView : NSTableView {}
+- (NSInteger)rowForItem:(id)item;
+ at end
+
+ at class NSArray, NSDictionary, NSMutableArray, NSNotification, NSString, NSToolbarItem, NSWindow;
+ at protocol XCProxyObjectProtocol
+- (id) representedObject;
+ at end
+
+ at interface PBXObject : NSObject {} @end
+typedef enum
+{
+    PBXNoItemChanged = 0x00,     PBXProjectItemChanged = 0x01,     PBXReferenceChanged = 0x02,     PBXGroupChanged = 0x04,     PBXTargetChanged = 0x08,     PBXBuildPhaseChanged = 0x10,     PBXBuildFileChanged = 0x20,     PBXBreakpointChanged = 0x40,
+}
+
+PBXChangedItemMask;
+ at protocol PBXChangeNotification 
+- (void)willChange;
+ at end
+
+ at class PBXContainer, PBXProject;
+ at interface PBXContainerItem : PBXObject <PBXChangeNotification> {} @end
+
+ at interface PBXProjectItem : PBXContainerItem {} @end
+
+ at class XCObjectGraphPath;
+ at protocol XCCompatibilityChecking  
+- (void)findFeaturesInUseAndAddToSet:(NSMutableSet *)featureSet usingPathPrefix:(XCObjectGraphPath *)pathPrefix;
+- (NSString *)identifier;
+ at end
+
+ at protocol XCConfigurationInspectables <NSObject> 
+- (NSString *)name;
+ at end
+
+ at class PBXProject, PBXFileReference, PBXBuildPhase, PBXBuildSettingsDictionary, PBXExecutable, PBXBuildFile, PBXTargetDependency, PBXBuildLog, PBXBuildRule, XCCommandLineToolSpecification, XCProductTypeSpecification, PBXPackageTypeSpecification, PBXTargetBuildContext, XCBuildConfiguration, XCConfigurationList, XCHeadersBuildPhaseDGSnapshot, XCResourcesBuildPhaseDGSnapshot, XCSourcesBuildPhaseDGSnapshot, XCFrameworksBuildPhaseDGSnapshot, XCRezBuildPhaseDGSnapshot, XCJavaArchiveBuildPhaseDGSnapshot, XCBuildFileRefDGSnapshot, XCWorkQueue, XCBuildOperation, XCStringList, XCPropertyExpansionContext, XCWorkQueueOperation, XCTargetDGSnapshot, XCTargetHeadermapCreationInfo, XCPropertyInfoContext, XCConfigurationInspectionContext, PBXReference;
+ at interface PBXTarget : PBXProjectItem <XCCompatibilityChecking, XCConfigurationInspectables> {} @end
+
+extern NSString * const XCTargetDGSnapshotContextKey_BuildAction;
+ at interface PBXBookmarkItem : PBXProjectItem {} @end
+
+ at interface PBXReference : PBXContainerItem {} @end
+
+extern BOOL PBX_getUsesTabsPreference();
+ at interface PBXGroup : PBXReference <XCCompatibilityChecking> {} @end
+
+ at class PBXFileReference, PBXTarget, PBXProject;
+ at interface PBXExecutable : PBXProjectItem {} @end
+
+ at class XCSCMRevisionInfo;
+ at interface PBXBookmark : PBXBookmarkItem {} @end
+
+ at class XCSCMInfo;
+ at interface PBXFileReference : PBXReference {} @end
+
+ at interface PBXLegacyTarget : PBXTarget {} @end
+
+ at interface PBXVariantGroup : PBXGroup {} @end
+
+typedef enum
+{
+    PBXBuildMessageType_None,     PBXBuildMessageType_Notice,     PBXBuildMessageType_Warning,     PBXBuildMessageType_Error,
+}
+
+PBXBuildMessageType;
+ at interface PBXBuildMessage : NSObject {} @end
+
+ at class PBXBreakpoint, PBXFileReference, PBXProject, PBXTextBookmark;
+ at protocol PBXMarkerDelegateProtocol <NSObject>
+- (void) setLineNumber:(NSUInteger)newLineNumber;
+ at end
+
+typedef enum
+{
+    PBXBreakpointIgnoreCountType = 0,  PBXBreakpointMultipleCountType
+}
+
+PBXBreakpointCountType;
+
+ at interface PBXBreakpoint : PBXProjectItem {} @end
+ at interface PBXFileBreakpoint : PBXBreakpoint <NSCopying, PBXMarkerDelegateProtocol> {} @end
+
+extern NSString *XCBreakpointActionsWereUpdated;
+ at protocol PBXNodeEditingProtocol
+- (BOOL) canRename;
+ at end
+
+ at protocol XCFosterParentHostProtocol
+- (void) reloadDataForProxies;
+ at end
+
+ at interface PBXBuildLogItem : NSObject {} @end
+
+ at interface PBXBuildLogMessageItem : PBXBuildLogItem {} @end
+
+extern NSString *PBXWindowDidChangeFirstResponderNotification;
+ at interface PBXModule : NSWindowController {} @end
+typedef enum
+{
+    PBXPanelCanChooseFiles,     PBXPanelCanChooseFolders,     PBXPanelCanChooseBoth,     PBXPanelCanChooseOnlyExistingFolders
+}
+
+PBXPanelSelection;
+ at interface XCSelection : NSResponder {} @end
+
+ at protocol XCSelectionSource
+- (XCSelection *) xcSelection;
+ at end
+typedef enum
+{
+    PBXFindMatchContains,     PBXFindMatchStartsWith,     PBXFindMatchWholeWords,     PBXFindMatchEndsWith
+}
+
+PBXFindMatchStyle;
+ at protocol PBXSelectableText
+- (NSString *)selectedString;
+ at end
+
+ at protocol PBXFindableText <PBXSelectableText>  
+- (BOOL)findText:(NSString *)string ignoreCase:(BOOL)ignoreCase matchStyle:(PBXFindMatchStyle)matchStyle backwards:(BOOL)backwards wrap:(BOOL)wrap;
+ at end
+
+ at class PBXProjectDocument, PBXProject, PBXAttributedStatusView;
+ at interface PBXProjectModule : PBXModule <PBXFindableText> {} @end
+
+ at class PBXExtendedOutlineView, PBXFileReference, PBXGroup, PBXProject, PBXProjectDocument, PBXReference, PBXOutlineDataSourceSplitter, XCSCMInfo;
+extern NSString * const PBXGroupTreeMainColumnIdentifier;
+ at interface PBXGroupTreeModule : PBXProjectModule {} @end
+
+ at protocol PBXTableColumnProvider  
+- (NSArray *) optionalColumnIdentifiers:(NSTableView *)tableView;
+ at end
+
+extern NSString *PBXSmartGroupTreeModuleColumnsKey;
+ at interface PBXSmartGroupTreeModule : PBXGroupTreeModule <PBXTableColumnProvider, XCSelectionSource, XCFosterParentHostProtocol> {} @end
+
+ at class PBXBookmark, PBXProjectModule, PBXProjectDocument, PBXSmartGroupTreeModule, PBXBreakpoint, XCBreakpointsBucket, PBXFileNavigator;
+ at interface PBXFosterParent : PBXGroup <XCProxyObjectProtocol, PBXNodeEditingProtocol> {} @end
+
+ at class NSString, NSAttributedString, PBXBookmark, PBXFileDocument, PBXSymbol, PBXDocBookmark;
+ at interface PBXFindResult : NSObject {} @end
+
+ at protocol PBXBookmarkSupport
+- (PBXBookmark *) bookmark;
+ at end
+
+ at interface PBXReference (BookmarkSupportAPI) <PBXBookmarkSupport> @end
+
+ at interface PBXBookmark (BookmarkSupportAPI) <PBXBookmarkSupport> @end
+
+ at interface PBXFileReference (BookmarkSupportAPI) <PBXBookmarkSupport> @end
+
+ at interface PBXTarget (BookmarkSupportAPI) <PBXBookmarkSupport> @end
+
+ at interface PBXLegacyTarget (BookmarkSupportAPI) <PBXBookmarkSupport> @end
+
+ at interface PBXExecutable (BookmarkSupportAPI) <PBXBookmarkSupport> @end
+
+ at interface PBXFosterParent (BookmarkSupportAPI) <PBXBookmarkSupport> @end
+
+ at interface PBXVariantGroup (BookmarkSupportAPI) <PBXBookmarkSupport> @end
+
+ at interface PBXFindResult (BookmarkSupportAPI) <PBXBookmarkSupport> @end
+
+ at interface PBXBuildMessage (BookmarkSupportAPI) <PBXBookmarkSupport> @end
+
+ at interface PBXBuildLogMessageItem (BookmarkSupportAPI) <PBXBookmarkSupport> @end
+
+ at interface PBXFileBreakpoint (BookmarkSupportAPI) <PBXBookmarkSupport> @end
+
+extern BOOL PBXShouldIncludeReference(id ref);
+ at class PBXSmartGroupDataSource, PBXModule, PBXSmartGroupBinding, PBXProjectModule, PBXFosterParent, PBXExtendedOutlineView, PBXOutlineViewCell, PBXProjectWorkspaceModule;
+ at protocol XCOutlineViewCheckBoxProtocol
+- (void) toggleEnabledState;
+- (void) storeCheckBoxBounds:(NSRect)bounds;
+ at end
+
+extern NSControlTint _NSDefaultControlTint(void);
+ at implementation PBXSmartGroupTreeModule
+- (void) dealloc
+{
+    [super dealloc];
+}
+
+- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(PBXOutlineViewCell *)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
+{
+    if ([[tableColumn identifier] isEqualToString: PBXGroupTreeMainColumnIdentifier])
+    {
+        if ([item conformsToProtocol:@protocol(XCOutlineViewCheckBoxProtocol)])
+        {
+            NSInteger columnIndex = [outlineView columnWithIdentifier:[tableColumn identifier]];
+            NSInteger row = [outlineView rowForItem:item];
+            <XCOutlineViewCheckBoxProtocol> xxx;
+            if (row > -1 && columnIndex > -1)
+            {
+                // FIXME: need to associate the correct type with this.
+                [(<XCOutlineViewCheckBoxProtocol>)item storeCheckBoxBounds:[cell imageRectForBounds:[outlineView frameOfCellAtColumn:columnIndex row:row]]]; // expected-error{{bad receiver type 'int'}}
+            }
+        }
+    }
+}
+





More information about the cfe-commits mailing list