From d3ded1ffacf1a47ffae151e10c7f74b19c2ef57d Mon Sep 17 00:00:00 2001 From: Steve Naroff Date: Thu, 5 Jun 2008 00:02:44 +0000 Subject: [PATCH] Support "

" as a short-hand for "id

". Here's a comment from GCC (the only documentation I could find on it). /* Make "" equivalent to "id " - nisse@lysator.liu.se. */ This commit adds the parser magic. The type associated with

is still incorrect. Will discuss with Chris. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51972 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Parse/ParseDecl.cpp | 22 +- test/Sema/bogus-gcc-protocol-extension.m | 300 +++++++++++++++++++++++ 2 files changed, 321 insertions(+), 1 deletion(-) create mode 100644 test/Sema/bogus-gcc-protocol-extension.m diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index f20c72e61c..46246e64ba 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -323,7 +323,7 @@ void Parser::ParseSpecifierQualifierList(DeclSpec &DS) { // 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 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS) { 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 ProtocolRefs; + ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc); + llvm::SmallVector *ProtocolDecl = + new llvm::SmallVector; + 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 @@ bool Parser::isTypeSpecifierQualifier() const { 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 @@ bool Parser::isDeclarationSpecifier() const { // GNU attributes. case tok::kw___attribute: + + // GNU bizarre protocol extension. FIXME: make an extension? + case tok::less: return true; // typedef-name diff --git a/test/Sema/bogus-gcc-protocol-extension.m b/test/Sema/bogus-gcc-protocol-extension.m new file mode 100644 index 0000000000..e2fc888d63 --- /dev/null +++ b/test/Sema/bogus-gcc-protocol-extension.m @@ -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; +@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; +@protocol NSObject +- (BOOL)isEqual:(id)object; +- (BOOL)conformsToProtocol:(Protocol *)aProtocol; +@end + +@protocol NSCopying +- (id)copyWithZone:(NSZone *)zone; +@end + +@protocol NSMutableCopying +- (id)mutableCopyWithZone:(NSZone *)zone; +@end + +@protocol NSCoding +- (void)encodeWithCoder:(NSCoder *)aCoder; +@end + +@interface NSObject {} + +- (void)dealloc; +@end + +extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone); + +typedef struct _NSSize {} NSRect; +typedef struct {} NSFastEnumerationState; + +@protocol NSFastEnumeration +- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len; +@end + +@class NSString; +@interface NSString : NSObject +- (NSUInteger)length; +- (BOOL)isEqualToString:(NSString *)aString; +@end + +@interface NSSimpleCString : NSString {} @end + +@interface NSConstantString : NSSimpleCString @end + +extern void *_NSConstantStringClassReference; + +@interface NSSet : NSObject +- (NSUInteger)count; +@end + +@interface NSMutableSet : NSSet +- (void)addObject:(id)object; +@end + +@class NSArray, NSDictionary, NSMapTable; +@interface NSResponder : NSObject {} @end + +@protocol NSAnimatablePropertyContainer +- (id)animator; +@end + +extern NSString *NSAnimationTriggerOrderIn ; +@interface NSView : NSResponder {} @end + +extern NSString * const NSFullScreenModeAllScreens; +typedef NSUInteger NSControlTint; + +@interface NSCell : NSObject {} +- (NSRect)imageRectForBounds:(NSRect)theRect; +@end + +@protocol NSValidatedUserInterfaceItem +- (SEL)action; +@end + +@protocol NSUserInterfaceValidations +- (BOOL)validateUserInterfaceItem:(id )anItem; +@end + +@class NSCell, NSFont, NSTextView, NSNotification, NSAttributedString, NSFormatter; +@interface NSControl : NSView {} @end + +@class NSColor, NSClipView, NSRulerView, NSScroller; +@interface NSWindowController : NSResponder {} @end + +@class NSTableHeaderView; +@class NSTableColumn; +@interface NSTableView : NSControl {} + +- (NSInteger)columnWithIdentifier:(id)identifier; +- (NSRect)frameOfCellAtColumn:(NSInteger)column row:(NSInteger)row; +@end + +@class NSButtonCell; +@interface NSOutlineView : NSTableView {} +- (NSInteger)rowForItem:(id)item; +@end + +@class NSArray, NSDictionary, NSMutableArray, NSNotification, NSString, NSToolbarItem, NSWindow; +@protocol XCProxyObjectProtocol +- (id) representedObject; +@end + +@interface PBXObject : NSObject {} @end +typedef enum +{ + PBXNoItemChanged = 0x00, PBXProjectItemChanged = 0x01, PBXReferenceChanged = 0x02, PBXGroupChanged = 0x04, PBXTargetChanged = 0x08, PBXBuildPhaseChanged = 0x10, PBXBuildFileChanged = 0x20, PBXBreakpointChanged = 0x40, +} + +PBXChangedItemMask; +@protocol PBXChangeNotification +- (void)willChange; +@end + +@class PBXContainer, PBXProject; +@interface PBXContainerItem : PBXObject {} @end + +@interface PBXProjectItem : PBXContainerItem {} @end + +@class XCObjectGraphPath; +@protocol XCCompatibilityChecking +- (void)findFeaturesInUseAndAddToSet:(NSMutableSet *)featureSet usingPathPrefix:(XCObjectGraphPath *)pathPrefix; +- (NSString *)identifier; +@end + +@protocol XCConfigurationInspectables +- (NSString *)name; +@end + +@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; +@interface PBXTarget : PBXProjectItem {} @end + +extern NSString * const XCTargetDGSnapshotContextKey_BuildAction; +@interface PBXBookmarkItem : PBXProjectItem {} @end + +@interface PBXReference : PBXContainerItem {} @end + +extern BOOL PBX_getUsesTabsPreference(); +@interface PBXGroup : PBXReference {} @end + +@class PBXFileReference, PBXTarget, PBXProject; +@interface PBXExecutable : PBXProjectItem {} @end + +@class XCSCMRevisionInfo; +@interface PBXBookmark : PBXBookmarkItem {} @end + +@class XCSCMInfo; +@interface PBXFileReference : PBXReference {} @end + +@interface PBXLegacyTarget : PBXTarget {} @end + +@interface PBXVariantGroup : PBXGroup {} @end + +typedef enum +{ + PBXBuildMessageType_None, PBXBuildMessageType_Notice, PBXBuildMessageType_Warning, PBXBuildMessageType_Error, +} + +PBXBuildMessageType; +@interface PBXBuildMessage : NSObject {} @end + +@class PBXBreakpoint, PBXFileReference, PBXProject, PBXTextBookmark; +@protocol PBXMarkerDelegateProtocol +- (void) setLineNumber:(NSUInteger)newLineNumber; +@end + +typedef enum +{ + PBXBreakpointIgnoreCountType = 0, PBXBreakpointMultipleCountType +} + +PBXBreakpointCountType; + +@interface PBXBreakpoint : PBXProjectItem {} @end +@interface PBXFileBreakpoint : PBXBreakpoint {} @end + +extern NSString *XCBreakpointActionsWereUpdated; +@protocol PBXNodeEditingProtocol +- (BOOL) canRename; +@end + +@protocol XCFosterParentHostProtocol +- (void) reloadDataForProxies; +@end + +@interface PBXBuildLogItem : NSObject {} @end + +@interface PBXBuildLogMessageItem : PBXBuildLogItem {} @end + +extern NSString *PBXWindowDidChangeFirstResponderNotification; +@interface PBXModule : NSWindowController {} @end +typedef enum +{ + PBXPanelCanChooseFiles, PBXPanelCanChooseFolders, PBXPanelCanChooseBoth, PBXPanelCanChooseOnlyExistingFolders +} + +PBXPanelSelection; +@interface XCSelection : NSResponder {} @end + +@protocol XCSelectionSource +- (XCSelection *) xcSelection; +@end +typedef enum +{ + PBXFindMatchContains, PBXFindMatchStartsWith, PBXFindMatchWholeWords, PBXFindMatchEndsWith +} + +PBXFindMatchStyle; +@protocol PBXSelectableText +- (NSString *)selectedString; +@end + +@protocol PBXFindableText +- (BOOL)findText:(NSString *)string ignoreCase:(BOOL)ignoreCase matchStyle:(PBXFindMatchStyle)matchStyle backwards:(BOOL)backwards wrap:(BOOL)wrap; +@end + +@class PBXProjectDocument, PBXProject, PBXAttributedStatusView; +@interface PBXProjectModule : PBXModule {} @end + +@class PBXExtendedOutlineView, PBXFileReference, PBXGroup, PBXProject, PBXProjectDocument, PBXReference, PBXOutlineDataSourceSplitter, XCSCMInfo; +extern NSString * const PBXGroupTreeMainColumnIdentifier; +@interface PBXGroupTreeModule : PBXProjectModule {} @end + +@protocol PBXTableColumnProvider +- (NSArray *) optionalColumnIdentifiers:(NSTableView *)tableView; +@end + +extern NSString *PBXSmartGroupTreeModuleColumnsKey; +@interface PBXSmartGroupTreeModule : PBXGroupTreeModule {} @end + +@class PBXBookmark, PBXProjectModule, PBXProjectDocument, PBXSmartGroupTreeModule, PBXBreakpoint, XCBreakpointsBucket, PBXFileNavigator; +@interface PBXFosterParent : PBXGroup {} @end + +@class NSString, NSAttributedString, PBXBookmark, PBXFileDocument, PBXSymbol, PBXDocBookmark; +@interface PBXFindResult : NSObject {} @end + +@protocol PBXBookmarkSupport +- (PBXBookmark *) bookmark; +@end + +@interface PBXReference (BookmarkSupportAPI) @end + +@interface PBXBookmark (BookmarkSupportAPI) @end + +@interface PBXFileReference (BookmarkSupportAPI) @end + +@interface PBXTarget (BookmarkSupportAPI) @end + +@interface PBXLegacyTarget (BookmarkSupportAPI) @end + +@interface PBXExecutable (BookmarkSupportAPI) @end + +@interface PBXFosterParent (BookmarkSupportAPI) @end + +@interface PBXVariantGroup (BookmarkSupportAPI) @end + +@interface PBXFindResult (BookmarkSupportAPI) @end + +@interface PBXBuildMessage (BookmarkSupportAPI) @end + +@interface PBXBuildLogMessageItem (BookmarkSupportAPI) @end + +@interface PBXFileBreakpoint (BookmarkSupportAPI) @end + +extern BOOL PBXShouldIncludeReference(id ref); +@class PBXSmartGroupDataSource, PBXModule, PBXSmartGroupBinding, PBXProjectModule, PBXFosterParent, PBXExtendedOutlineView, PBXOutlineViewCell, PBXProjectWorkspaceModule; +@protocol XCOutlineViewCheckBoxProtocol +- (void) toggleEnabledState; +- (void) storeCheckBoxBounds:(NSRect)bounds; +@end + +extern NSControlTint _NSDefaultControlTint(void); +@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]; + xxx; + if (row > -1 && columnIndex > -1) + { + // FIXME: need to associate the correct type with this. + [()item storeCheckBoxBounds:[cell imageRectForBounds:[outlineView frameOfCellAtColumn:columnIndex row:row]]]; // expected-error{{bad receiver type 'int'}} + } + } + } +} + -- 2.40.0