diff options
author | Steve Naroff <snaroff@apple.com> | 2009-03-09 21:12:44 +0000 |
---|---|---|
committer | Steve Naroff <snaroff@apple.com> | 2009-03-09 21:12:44 +0000 |
commit | 61f72cbd037e58f12cfe90cd442373f44092f030 (patch) | |
tree | 77292f6d4c23460429428e75f3309d662856586f /lib/Parse | |
parent | 35bd763b9438b53f7920521ed19c1ef74c7a6795 (diff) |
Implement property '.' notation on Factory/Class objects. Parser changes aren't very pretty:-(
This fixes <rdar://problem/6496506> Implement class setter/getter for properties.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66465 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse')
-rw-r--r-- | lib/Parse/ParseDecl.cpp | 4 | ||||
-rw-r--r-- | lib/Parse/ParseExpr.cpp | 22 | ||||
-rw-r--r-- | lib/Parse/ParseObjc.cpp | 17 |
3 files changed, 29 insertions, 14 deletions
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index bbe074a8fb..5bf9783cfb 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -1437,6 +1437,10 @@ bool Parser::isDeclarationSpecifier() { default: return false; case tok::identifier: // foo::bar + // Unfortunate hack to support "Class.factoryMethod" notation. + if (getLang().ObjC1 && NextToken().is(tok::period)) + return false; + // Annotate typenames and C++ scope specifiers. If we get one, just // recurse to handle whatever we get. if (TryAnnotateTypeOrScopeToken()) diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index 331f3181cd..000cb9d606 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -569,6 +569,28 @@ Parser::OwningExprResult Parser::ParseCastExpression(bool isUnaryExpression, return ParseCastExpression(isUnaryExpression, isAddressOfOperand); } + // Support 'Class.property' notation. + // We don't use isTokObjCMessageIdentifierReceiver(), since it allows + // 'super' (which is inappropriate here). + if (getLang().ObjC1 && + Actions.getTypeName(*Tok.getIdentifierInfo(), + Tok.getLocation(), CurScope) && + NextToken().is(tok::period)) { + IdentifierInfo &ReceiverName = *Tok.getIdentifierInfo(); + SourceLocation IdentLoc = ConsumeToken(); + SourceLocation DotLoc = ConsumeToken(); + + if (Tok.isNot(tok::identifier)) { + Diag(Tok, diag::err_expected_ident); + return ExprError(); + } + IdentifierInfo &PropertyName = *Tok.getIdentifierInfo(); + SourceLocation PropertyLoc = ConsumeToken(); + + Res = Actions.ActOnClassPropertyRefExpr(ReceiverName, PropertyName, + IdentLoc, PropertyLoc); + return move(Res); + } // Consume the identifier so that we can see if it is followed by a '('. // Function designators are allowed to be undeclared (C99 6.5.1p2), so we // need to know whether or not this identifier is a function designator or diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp index e9bb3d7c31..8a3672d29c 100644 --- a/lib/Parse/ParseObjc.cpp +++ b/lib/Parse/ParseObjc.cpp @@ -199,18 +199,6 @@ Parser::DeclTy *Parser::ParseObjCAtInterfaceDeclaration( return ClsType; } -/// constructSetterName - Return the setter name for the given -/// identifier, i.e. "set" + Name where the initial character of Name -/// has been capitalized. -static IdentifierInfo *constructSetterName(IdentifierTable &Idents, - const IdentifierInfo *Name) { - llvm::SmallString<100> SelectorName; - SelectorName = "set"; - SelectorName.append(Name->getName(), Name->getName()+Name->getLength()); - SelectorName[3] = toupper(SelectorName[3]); - return &Idents.get(&SelectorName[0], &SelectorName[SelectorName.size()]); -} - /// objc-interface-decl-list: /// empty /// objc-interface-decl-list objc-property-decl [OBJC2] @@ -340,8 +328,9 @@ void Parser::ParseObjCInterfaceDeclList(DeclTy *interfaceDecl, PP.getSelectorTable().getNullarySelector(SelName); IdentifierInfo *SetterName = OCDS.getSetterName(); if (!SetterName) - SetterName = constructSetterName(PP.getIdentifierTable(), - FD.D.getIdentifier()); + SetterName = + SelectorTable::constructSetterName(PP.getIdentifierTable(), + FD.D.getIdentifier()); Selector SetterSel = PP.getSelectorTable().getUnarySelector(SetterName); bool isOverridingProperty = false; |