diff options
author | Chris Lattner <sabre@nondot.org> | 2009-10-25 17:04:48 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-10-25 17:04:48 +0000 |
commit | b7c3fd7b493329550c29dec11d31aca4d537e23e (patch) | |
tree | f9c414e93acf605324ce9377c42b6efcadb38fb4 /lib/Parse/ParseExpr.cpp | |
parent | 9994a34f6cf842721ba7723edc0b9036229fe387 (diff) |
In objc mode, every identifier in a cast expression was using doing a
type looking using getTypeName() and every property access was using
NextToken() to do lookahead to see if the identifier is followed by
a '.'. Rearrange this code to not need lookahead and only do the
type lookup if we have "identifier." in the token stream. Also
improve a diagnostic a bit.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85056 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/ParseExpr.cpp')
-rw-r--r-- | lib/Parse/ParseExpr.cpp | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index 7d056fdebb..8ebb7c01d8 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -623,36 +623,35 @@ 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(); + // Consume the identifier so that we can see if it is followed by a '(' or + // '.'. + IdentifierInfo &II = *Tok.getIdentifierInfo(); + SourceLocation ILoc = ConsumeToken(); + + // Support 'Class.property' notation. We don't use + // isTokObjCMessageIdentifierReceiver(), since it allows 'super' (which is + // inappropriate here). + if (getLang().ObjC1 && Tok.is(tok::period) && + Actions.getTypeName(II, ILoc, CurScope)) { SourceLocation DotLoc = ConsumeToken(); - + if (Tok.isNot(tok::identifier)) { - Diag(Tok, diag::err_expected_ident); + Diag(Tok, diag::err_expected_property_name); return ExprError(); } IdentifierInfo &PropertyName = *Tok.getIdentifierInfo(); SourceLocation PropertyLoc = ConsumeToken(); - - Res = Actions.ActOnClassPropertyRefExpr(ReceiverName, PropertyName, - IdentLoc, PropertyLoc); + + Res = Actions.ActOnClassPropertyRefExpr(II, PropertyName, + ILoc, PropertyLoc); // These can be followed by postfix-expr pieces. return ParsePostfixExpressionSuffix(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 // not. - IdentifierInfo &II = *Tok.getIdentifierInfo(); - SourceLocation L = ConsumeToken(); - Res = Actions.ActOnIdentifierExpr(CurScope, L, II, Tok.is(tok::l_paren)); + Res = Actions.ActOnIdentifierExpr(CurScope, ILoc, II, Tok.is(tok::l_paren)); // These can be followed by postfix-expr pieces. return ParsePostfixExpressionSuffix(move(Res)); } |