[cfe-commits] r42611 - in /cfe/trunk: Parse/ParseExpr.cpp Parse/ParseObjc.cpp Parse/ParseStmt.cpp Sema/SemaDecl.cpp include/clang/Parse/Parser.h test/Parser/encode.m test/Parser/objc-try-catch-1.m
Fariborz Jahanian
fjahanian at apple.com
Thu Oct 4 13:19:06 PDT 2007
Author: fjahanian
Date: Thu Oct 4 15:19:06 2007
New Revision: 42611
URL: http://llvm.org/viewvc/llvm-project?rev=42611&view=rev
Log:
this patch accomodates clattner's comments on expression processing in @try-statement.
Added:
cfe/trunk/test/Parser/encode.m
Modified:
cfe/trunk/Parse/ParseExpr.cpp
cfe/trunk/Parse/ParseObjc.cpp
cfe/trunk/Parse/ParseStmt.cpp
cfe/trunk/Sema/SemaDecl.cpp
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/test/Parser/objc-try-catch-1.m
Modified: cfe/trunk/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseExpr.cpp?rev=42611&r1=42610&r2=42611&view=diff
==============================================================================
--- cfe/trunk/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/Parse/ParseExpr.cpp Thu Oct 4 15:19:06 2007
@@ -177,7 +177,7 @@
/// routine is necessary to disambiguate @try-statement from,
/// for example, @encode-expression.
///
-Parser::ExprResult Parser::ParseExpressionWithLeadingAt(SourceLocation &AtLoc) {
+Parser::ExprResult Parser::ParseExpressionWithLeadingAt(SourceLocation AtLoc) {
ExprResult LHS = ParseObjCExpression(AtLoc);
if (LHS.isInvalid) return LHS;
Modified: cfe/trunk/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseObjc.cpp?rev=42611&r1=42610&r2=42611&view=diff
==============================================================================
--- cfe/trunk/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/Parse/ParseObjc.cpp Thu Oct 4 15:19:06 2007
@@ -1067,10 +1067,10 @@
/// objc-throw-statement:
/// throw expression[opt];
///
-Parser::DeclTy *Parser::ParseObjCThrowStmt(SourceLocation &atLoc) {
+Parser::DeclTy *Parser::ParseObjCThrowStmt(SourceLocation atLoc) {
ConsumeToken(); // consume throw
if (Tok.getKind() != tok::semi) {
- ExprResult Res = ParseAssignmentExpression();
+ ExprResult Res = ParseExpression();
if (Res.isInvalid) {
SkipUntil(tok::semi);
return 0;
@@ -1090,7 +1090,7 @@
/// parameter-declaration
/// '...' [OBJC2]
///
-Parser::DeclTy *Parser::ParseObjCTryStmt(SourceLocation &atLoc) {
+Parser::DeclTy *Parser::ParseObjCTryStmt(SourceLocation atLoc) {
bool catch_or_finally_seen = false;
ConsumeToken(); // consume try
if (Tok.getKind() != tok::l_brace) {
@@ -1172,21 +1172,21 @@
StmtResult FnBody = ParseCompoundStatementBody();
}
-Parser::ExprResult Parser::ParseObjCExpression(SourceLocation &AtLoc) {
+Parser::ExprResult Parser::ParseObjCExpression(SourceLocation AtLoc) {
switch (Tok.getKind()) {
case tok::string_literal: // primary-expression: string-literal
case tok::wide_string_literal:
- return ParseObjCStringLiteral();
+ return ParsePostfixExpressionSuffix(ParseObjCStringLiteral());
default:
break;
}
switch (Tok.getIdentifierInfo()->getObjCKeywordID()) {
case tok::objc_encode:
- return ParseObjCEncodeExpression();
+ return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression());
case tok::objc_protocol:
- return ParseObjCProtocolExpression();
+ return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression());
default:
Diag(AtLoc, diag::err_unexpected_at);
SkipUntil(tok::semi);
Modified: cfe/trunk/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseStmt.cpp?rev=42611&r1=42610&r2=42611&view=diff
==============================================================================
--- cfe/trunk/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/Parse/ParseStmt.cpp Thu Oct 4 15:19:06 2007
@@ -34,8 +34,8 @@
/// selection-statement
/// iteration-statement
/// jump-statement
-/// [OBC] objc-throw-statement [TODO]
-/// [OBC] objc-try-catch-statement [TODO]
+/// [OBC] objc-throw-statement
+/// [OBC] objc-try-catch-statement
/// [OBC] objc-synchronized-statement [TODO]
/// [GNU] asm-statement
/// [OMP] openmp-construct [TODO]
@@ -64,9 +64,9 @@
/// 'return' expression[opt] ';'
/// [GNU] 'goto' '*' expression ';'
///
-/// [OBC] objc-throw-statement: [TODO]
-/// [OBC] '@' 'throw' expression ';' [TODO]
-/// [OBC] '@' 'throw' ';' [TODO]
+/// [OBC] objc-throw-statement:
+/// [OBC] '@' 'throw' expression ';'
+/// [OBC] '@' 'throw' ';'
///
Parser::StmtResult Parser::ParseStatementOrDeclaration(bool OnlyStatement) {
const char *SemiError = 0;
@@ -91,19 +91,28 @@
return ParseObjCTryStmt(AtLoc);
else if (Tok.getIdentifierInfo()->getObjCKeywordID() == tok::objc_throw)
return ParseObjCThrowStmt(AtLoc);
+ ExprResult Res = ParseExpressionWithLeadingAt(AtLoc);
+ if (Res.isInvalid) {
+ // If the expression is invalid, skip ahead to the next semicolon. Not
+ // doing this opens us up to the possibility of infinite loops if
+ // ParseExpression does not consume any tokens.
+ SkipUntil(tok::semi);
+ return true;
+ }
+ // Otherwise, eat the semicolon.
+ ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr);
+ return Actions.ActOnExprStmt(Res.Val);
}
- // Fall thru.
default:
- if (Kind != tok::at && !OnlyStatement && isDeclarationSpecifier()) {
+ if (!OnlyStatement && isDeclarationSpecifier()) {
return Actions.ActOnDeclStmt(ParseDeclaration(Declarator::BlockContext));
} else if (Tok.getKind() == tok::r_brace) {
Diag(Tok, diag::err_expected_statement);
return true;
} else {
// expression[opt] ';'
- ExprResult Res = (Kind == tok::at) ? ParseExpressionWithLeadingAt(AtLoc)
- : ParseExpression();
+ ExprResult Res = ParseExpression();
if (Res.isInvalid) {
// If the expression is invalid, skip ahead to the next semicolon. Not
// doing this opens us up to the possibility of infinite loops if
Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=42611&r1=42610&r2=42611&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Thu Oct 4 15:19:06 2007
@@ -1729,27 +1729,28 @@
if (IDecl)
ImplMethodsVsClassMethods(ImplClass, IDecl);
}
- else if (isa<ObjcCategoryImplDecl>(static_cast<Decl *>(ClassDecl))) {
- ObjcCategoryImplDecl* CatImplClass = cast<ObjcCategoryImplDecl>(
+ else {
+ ObjcCategoryImplDecl* CatImplClass = dyn_cast<ObjcCategoryImplDecl>(
static_cast<Decl*>(ClassDecl));
- CatImplClass->ObjcAddCatImplMethods(&insMethods[0], insMethods.size(),
- &clsMethods[0], clsMethods.size());
- ObjcInterfaceDecl* IDecl = CatImplClass->getClassInterface();
- // Find category interface decl and then check that all methods declared
- // in this interface is implemented in the category @implementation.
- if (IDecl) {
- for (ObjcCategoryDecl *Categories = IDecl->getListCategories();
- Categories; Categories = Categories->getNextClassCategory()) {
- if (Categories->getCatName() == CatImplClass->getObjcCatName()) {
- ImplCategoryMethodsVsIntfMethods(CatImplClass, Categories);
- break;
+ if (CatImplClass) {
+ CatImplClass->ObjcAddCatImplMethods(&insMethods[0], insMethods.size(),
+ &clsMethods[0], clsMethods.size());
+ ObjcInterfaceDecl* IDecl = CatImplClass->getClassInterface();
+ // Find category interface decl and then check that all methods declared
+ // in this interface is implemented in the category @implementation.
+ if (IDecl) {
+ for (ObjcCategoryDecl *Categories = IDecl->getListCategories();
+ Categories; Categories = Categories->getNextClassCategory()) {
+ if (Categories->getCatName() == CatImplClass->getObjcCatName()) {
+ ImplCategoryMethodsVsIntfMethods(CatImplClass, Categories);
+ break;
+ }
}
}
}
+ else
+ assert(0 && "Sema::ActOnAddMethodsToObjcDecl(): Unknown DeclTy");
}
- else
- assert(0 && "Sema::ActOnAddMethodsToObjcDecl(): Unknown DeclTy");
- return;
}
Sema::DeclTy *Sema::ActOnMethodDeclaration(SourceLocation MethodLoc,
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=42611&r1=42610&r2=42611&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Thu Oct 4 15:19:06 2007
@@ -272,8 +272,8 @@
DeclTy *ParseObjCAtAliasDeclaration(SourceLocation atLoc);
DeclTy *ParseObjCPropertySynthesize(SourceLocation atLoc);
DeclTy *ParseObjCPropertyDynamic(SourceLocation atLoc);
- DeclTy *ParseObjCTryStmt(SourceLocation &atLoc);
- DeclTy *ParseObjCThrowStmt(SourceLocation &atLoc);
+ DeclTy *ParseObjCTryStmt(SourceLocation atLoc);
+ DeclTy *ParseObjCThrowStmt(SourceLocation atLoc);
IdentifierInfo *ParseObjCSelector();
// Definitions for Objective-c context sensitive keywords recognition.
@@ -317,7 +317,7 @@
ExprResult ParseAssignmentExpression(); // Expr that doesn't include commas.
ExprResult ParseExpressionWithLeadingIdentifier(const Token &Tok);
- ExprResult ParseExpressionWithLeadingAt(SourceLocation &AtLoc);
+ ExprResult ParseExpressionWithLeadingAt(SourceLocation AtLoc);
ExprResult ParseAssignmentExprWithLeadingIdentifier(const Token &Tok);
ExprResult ParseAssignmentExpressionWithLeadingStar(const Token &Tok);
@@ -363,7 +363,7 @@
//===--------------------------------------------------------------------===//
// Objective-C Expressions
- ExprResult ParseObjCExpression(SourceLocation &AtLocation);
+ ExprResult ParseObjCExpression(SourceLocation AtLocation);
ExprResult ParseObjCStringLiteral();
ExprResult ParseObjCEncodeExpression();
ExprResult ParseObjCProtocolExpression();
Added: cfe/trunk/test/Parser/encode.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/encode.m?rev=42611&view=auto
==============================================================================
--- cfe/trunk/test/Parser/encode.m (added)
+++ cfe/trunk/test/Parser/encode.m Thu Oct 4 15:19:06 2007
@@ -0,0 +1,8 @@
+// RUN: clang -fsyntax-only -verify %s
+
+int main(void) {
+ const char ch = @encode(char *)[2];
+ char c = @encode(char *)[2] + 4;
+ return c;
+}
+
Modified: cfe/trunk/test/Parser/objc-try-catch-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-try-catch-1.m?rev=42611&r1=42610&r2=42611&view=diff
==============================================================================
--- cfe/trunk/test/Parser/objc-try-catch-1.m (original)
+++ cfe/trunk/test/Parser/objc-try-catch-1.m Thu Oct 4 15:19:06 2007
@@ -1,3 +1,5 @@
+// RUN: clang -fsyntax-only -verify %s
+
void * proc();
@interface Frob
@@ -22,7 +24,7 @@
return proc();
}
@catch (Frob* ex) {
- @throw;
+ @throw 1,2;
}
@catch(...) {
@throw (4,3,proc());
More information about the cfe-commits
mailing list