summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-10-25 17:04:48 +0000
committerChris Lattner <sabre@nondot.org>2009-10-25 17:04:48 +0000
commit5566290b341e42a2db22ffe3fad927568995111c (patch)
tree31dce2f0f5cedf159b7bad3fb4aa2c07e0c74af6
parent1054faed320dd781a31338493d7368b3789c141f (diff)
downloadbcm5719-llvm-5566290b341e42a2db22ffe3fad927568995111c.tar.gz
bcm5719-llvm-5566290b341e42a2db22ffe3fad927568995111c.zip
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. llvm-svn: 85056
-rw-r--r--clang/include/clang/Basic/DiagnosticParseKinds.td1
-rw-r--r--clang/lib/Parse/ParseExpr.cpp35
-rw-r--r--clang/lib/Sema/SemaDecl.cpp2
3 files changed, 19 insertions, 19 deletions
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td
index a7f3441e301..add979a1991 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -126,6 +126,7 @@ def err_expected_asm_operand : Error<
"expected string literal or '[' for asm operand">;
def err_expected_selector_for_method : Error<
"expected selector for Objective-C method">;
+def err_expected_property_name : Error<"expected property name">;
def err_unexpected_at : Error<"unexpected '@' in program">;
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 7d056fdebb9..8ebb7c01d85 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/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));
}
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index fe8052981f2..4858321d51e 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -142,7 +142,7 @@ Sema::TypeTy *Sema::getTypeName(IdentifierInfo &II, SourceLocation NameLoc,
QualType T;
if (TypeDecl *TD = dyn_cast<TypeDecl>(IIDecl)) {
- // Check whether we can use this type
+ // Check whether we can use this type.
(void)DiagnoseUseOfDecl(IIDecl, NameLoc);
if (getLangOptions().CPlusPlus) {
OpenPOWER on IntegriCloud