aboutsummaryrefslogtreecommitdiff
path: root/lib/Parse/ParseDecl.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-03-29 17:18:04 +0000
committerChris Lattner <sabre@nondot.org>2009-03-29 17:18:04 +0000
commit23c4b1883b13dc17484b7214091b73f3ba29096e (patch)
tree86531eaa799afb588283057ad8ddea9d00723e25 /lib/Parse/ParseDecl.cpp
parent40f1265ebd42ece3e7f7917319b56012e8e2bce2 (diff)
hoist checks for ; and in out of ParseInitDeclaratorListAfterFirstDeclarator
into ParseSimpleDeclaration, and improve a diagnostic. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68009 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/ParseDecl.cpp')
-rw-r--r--lib/Parse/ParseDecl.cpp56
1 files changed, 28 insertions, 28 deletions
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp
index 1f8522f094..5de4dd4a7c 100644
--- a/lib/Parse/ParseDecl.cpp
+++ b/lib/Parse/ParseDecl.cpp
@@ -273,7 +273,30 @@ Parser::DeclGroupPtrTy Parser::ParseSimpleDeclaration(unsigned Context) {
Declarator DeclaratorInfo(DS, (Declarator::TheContext)Context);
ParseDeclarator(DeclaratorInfo);
- return ParseInitDeclaratorListAfterFirstDeclarator(DeclaratorInfo);
+ DeclGroupPtrTy DG =
+ ParseInitDeclaratorListAfterFirstDeclarator(DeclaratorInfo);
+
+ if (Tok.is(tok::semi)) {
+ ConsumeToken();
+ // for(is key; in keys) is error.
+ if (Context == Declarator::ForContext && isTokIdentifier_in())
+ Diag(Tok, diag::err_parse_error);
+
+ return DG;
+ }
+
+ // If this is an ObjC2 for-each loop, this is a successful declarator
+ // parse. The syntax for these looks like:
+ // 'for' '(' declaration 'in' expr ')' statement
+ if (Context == Declarator::ForContext && isTokIdentifier_in())
+ return DG;
+
+ Diag(Tok, diag::err_expected_semi_declation);
+ // Skip to end of block or statement
+ SkipUntil(tok::r_brace, true, true);
+ if (Tok.is(tok::semi))
+ ConsumeToken();
+ return DG;
}
@@ -315,7 +338,7 @@ ParseInitDeclaratorListAfterFirstDeclarator(Declarator &D) {
SourceLocation Loc;
OwningExprResult AsmLabel(ParseSimpleAsm(&Loc));
if (AsmLabel.isInvalid()) {
- SkipUntil(tok::semi);
+ SkipUntil(tok::semi, true, true);
return DeclGroupPtrTy();
}
@@ -343,7 +366,7 @@ ParseInitDeclaratorListAfterFirstDeclarator(Declarator &D) {
} else {
OwningExprResult Init(ParseInitializer());
if (Init.isInvalid()) {
- SkipUntil(tok::semi);
+ SkipUntil(tok::semi, true, true);
return DeclGroupPtrTy();
}
Actions.AddInitializerToDecl(ThisDecl, move(Init));
@@ -400,31 +423,8 @@ ParseInitDeclaratorListAfterFirstDeclarator(Declarator &D) {
ParseDeclarator(D);
}
- if (Tok.is(tok::semi)) {
- ConsumeToken();
- // for(is key; in keys) is error.
- if (D.getContext() == Declarator::ForContext && isTokIdentifier_in()) {
- Diag(Tok, diag::err_parse_error);
- return DeclGroupPtrTy();
- }
-
- return Actions.FinalizeDeclaratorGroup(CurScope, &DeclsInGroup[0],
- DeclsInGroup.size());
- }
-
- // If this is an ObjC2 for-each loop, this is a successful declarator
- // parse. The syntax for these looks like:
- // 'for' '(' declaration 'in' expr ')' statement
- if (D.getContext() == Declarator::ForContext && isTokIdentifier_in())
- return Actions.FinalizeDeclaratorGroup(CurScope, &DeclsInGroup[0],
- DeclsInGroup.size());
-
- Diag(Tok, diag::err_parse_error);
- // Skip to end of block or statement
- SkipUntil(tok::r_brace, true, true);
- if (Tok.is(tok::semi))
- ConsumeToken();
- return DeclGroupPtrTy();
+ return Actions.FinalizeDeclaratorGroup(CurScope, &DeclsInGroup[0],
+ DeclsInGroup.size());
}
/// ParseSpecifierQualifierList